File: vector2str.m

package info (click to toggle)
openems 0.0.35%2Bgit20190103.6a75e98%2Bdfsg.1-3.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,544 kB
  • sloc: cpp: 40,417; python: 2,028; yacc: 580; makefile: 459; lex: 350; sh: 176; ruby: 19
file content (35 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function str = vector2str(vec, acc)
% str = vector2str( vec [, acc] )
%
% internal function for CSXCAD
% 
% (c) 2012-2015 Thorsten Liebig <thorsten.liebig@gmx.de>
% (C) 2012 Sebastian Held <sebastian.held@gmx.de>

str = '';

if (numel(vec)==0)
    return
end

if (nargin<2)
    acc = 9;
end

% Octave < 3.8.0 has a bug in num2str() (only 64bit versions)
% see bug report https://savannah.gnu.org/bugs/index.php?36121
[isOct,version] = isOctave();
if (isOct && version.major <= 3 && version.minor < 8)
    % affected Octave versions
    for n = 1:numel(vec)
        str = [str sprintf('%.*g', acc, vec(n)) ','];
    end
else
    % Matlab and non affected Octave
    for n = 1:numel(vec)
        str = [str num2str(vec(n),acc) ','];
    end
end

% remove the last ','
str = str(1:end-1);