matlab - write data into the text output file -
i have input.dat that:
1 1 1 2 3 10 17 16 15 8 9 2 1 3 4 5 12 19 18 17 10 11 3 1 5 6 7 4 21 20 19 12 13 4 1 15 16 17 24 31 30 29 22 23
1st column : numel
2nd column : matno
3rd-12st column : lnods
i wrote follow;
fprintf(fid6,'n pro points \n'); matno=zeros(4,1); lnods=zeros(4,9); ielem=1:nelem numel(ielem,:)=fscanf(fid5, '%d', 1); matno(ielem,:)=fscanf(fid5, '%d', 1); lnods(ielem,:)=fscanf(fid5, '%d %d %d %d %d %d %d %d %d',[9,1]); end fprintf(fid6, '%-2d %-2d %-2d %-2d %-2d %-2d %-2d %-2d %-2d %-2d %- 2d\n',numel,matno,lnods);
i expect:
n pro points 1 1 1 2 3 10 17 16 15 8 9 2 1 3 4 5 12 19 18 17 10 11 3 1 5 6 7 4 21 20 19 12 13 4 1 15 16 17 24 31 30 29 22 23
but
n pro points 1 2 3 4 1 1 1 1 1 3 5 15 2 4 6 16 ...
what problem?
use tabs instead of plain spaces. cleaner.
for example:
fprintf(fid6, '%-2d\t%-2d\t%-2d %-2d %-2d %-2d %-2d %-2d %-2d %-2d %-2d\n',numel,matno,lnods);
and spacing, why put %-2d? try %4d or , remove whitespaces
fprintf(fid6,'%4d\t%4d\t%4d%4d%4d%4d%4d%4d%4d%4d%4d\n',numel,matno,lnods)
Comments
Post a Comment