fprintf中 '\n'无法实现换行??
如题两个矩阵 Num1(11,11),Num2(11,21)
for j=1:11 %(按列循环,写入文本)
fprintf(fid,'%2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d\n',Num1(:,j));
end
fclose(fid);
fid=fopen('Num2.txt','wt');
for jj=1:21%(按列循环,写入文本)
fprintf(fid,'%2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d\n',Num2(:,jj));
end
fclose(fid)
运行后Num1.txt 中数据 可以实现换行,有11行 11列
但Num1.txt 中数据只有1行 ?
请问,这个问题怎么解决?
谢谢 这个问题解决了,是我自己搞错了,
fprintf 是按列写入的,Num2(11,21)有11行,因此应该是如下程序
fid=fopen('Num2.txt','wt');
for jj=1:21%(按列循环,写入文本)
fprintf(fid,'%2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d\n',Num2(:,jj));
end
fclose(fid) 这样也可以!?
fid=fopen('Num2.txt','wt');
for jj=1:11%(按列循环,写入文本)
fprintf(fid,'%2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d\n',Num2(jj,:));
end
fclose(fid)
页:
[1]