Functions | |
function | dlmwrite (file, a, varargin) if(nargin< 2||!ischar(file)) print_usage() |
if (ischar(a)) precision | |
while (i< length(varargin)) i | |
if (strcmpi(varargin{i},"delimiter")) i | |
elseif (strcmpi(varargin{i},"newline")) i | |
if (strcmpi(newline,"unix")) new line | |
elseif (strcmpi(newline,"pc")) new line | |
elseif (strcmpi(newline,"mac")) new line | |
endif | elseif (strcmpi(varargin{i},"roffset")) i |
elseif (strcmpi(varargin{i},"coffset")) i | |
elseif (strcmpi(varargin{i},"precision")) i | |
if (!strcmpi(class(precision),"char")) precision | |
endif | elseif (strcmpi(varargin{i},"-append")) opentype |
elseif (strcmpi(varargin{i},"append")) i | |
if (strcmpi(varargin{i},"on")) opentype | |
elseif (strcmpi(varargin{i},"off")) opentype | |
else | error ("dlmwrite: append must be \"on\" or \"off\".") |
endif else | if (i==1) delim |
elseif (i==2) r | |
else | print_usage () |
if (fid< 0) error(msg) | |
else | if (r > 0) fprintf(fid |
else | repmat ([repmat(delim, 1, c+columns(a)-1), newline], 1, r)) |
endif | if (iscomplex(a)) cprecision |
endif | if (c > 0) template |
b (1:2:end,:) | |
b (2:2:end,:) | |
fprintf (fid, template, b) | |
else | fprintf (fid, template, a.') |
endif | fclose (fid) |
!dlmwrite (f,[1, 2;3, 4],'precision','%5.2f','newline','unix','roffset', 1,'coffset', 1) | |
!fclose (fid) | |
!dlmwrite (f,[5, 6],'precision','%5.2f','newline','unix','coffset', 1,'delimiter',',','-append') | |
!unlink (f) | |
!assert (f1,",,\n, 1.00, 2.00\n, 3.00, 4.00\n") | |
!assert (f2,",,\n, 1.00, 2.00\n, 3.00, 4.00\n, 5.00, 6.00\n") | |
Variables | |
endif | delim = "," |
r = 0 | |
c = 0 | |
newline = "\n" | |
else | precision = "%.16g" |
endif | opentype = "wt" |
i = 0 | |
endif endif | endwhile [fid, msg] = fopen (file, opentype) |
else | s |
template | |
b = zeros (2*rows(a), columns (a)) | |
endif endfunction!test | !f = tmpnam() |
!fid = fopen(f,"rt") | |
!f1 = char(fread(fid,Inf,'char')') | |
!f2 = char(fread(fid,Inf,'char')') |
!assert | ( | f2 | , | |
" | , | |||
\ | n, | |||
1. | 00, | |||
2.00\ | n, | |||
3. | 00, | |||
4.00\ | n, | |||
5. | 00, | |||
6.00\n" | ||||
) |
!assert | ( | f1 | , | |
" | , | |||
\ | n, | |||
1. | 00, | |||
2.00\ | n, | |||
3. | 00, | |||
4.00\n" | ||||
) |
!dlmwrite | ( | f | , | |
'precision' | , | |||
'%5.2f' | , | |||
'newline' | , | |||
'unix' | , | |||
'coffset' | , | |||
1 | , | |||
'delimiter' | , | |||
' | , | |||
' | , | |||
'-append' | ||||
) |
!fclose | ( | fid | ) |
!unlink | ( | f | ) |
b | ( | 2:2:end | , | |
: | ||||
) |
b | ( | 1:2:end | , | |
: | ||||
) |
elseif | ( | i | = =2 |
) |
elseif | ( | strcmpi(varargin{i},"off") | ) |
elseif | ( | strcmpi(varargin{i},"append") | ) |
endif elseif | ( | strcmpi(varargin{i},"-append") | ) |
elseif | ( | strcmpi(varargin{i},"precision") | ) |
elseif | ( | strcmpi(varargin{i},"coffset") | ) |
endif elseif | ( | strcmpi(varargin{i},"roffset") | ) |
elseif | ( | strcmpi(newline,"mac") | ) | [new] |
elseif | ( | strcmpi(newline,"pc") | ) | [new] |
elseif | ( | strcmpi(varargin{i},"newline") | ) |
else error | ( | "dlmwrite: append must be \"on\" or \"off\"." | ) |
endif if | ( | c | , | |
0 | ||||
) |
endif if | ( | iscomplex(a) | ) |
else if | ( | r | , | |
0 | ||||
) |
if | ( | ) |
if | ( | strcmpi(varargin{i},"on") | ) |
if | ( | ! | strcmpiclass(precision),"char" | ) |
if | ( | strcmpi(newline,"unix") | ) | [new] |
if | ( | strcmpi(varargin{i},"delimiter") | ) |
if | ( | ischar(a) | ) |
else print_usage | ( | ) |
else repmat | ( | 1 | , | |
r | ||||
) |
while | ( | ) |
endif endfunction !test !f = tmpnam() |
!f1 = char(fread(fid,Inf,'char')') |
!f2 = char(fread(fid,Inf,'char')') |
!fid = fopen(f,"rt") |
b = zeros (2*rows(a), columns (a)) |
c = 0 |
delim = "," |
i = 0 |
newline = "\n" |
precision = "%.16g" |
r = 0 |
else s |