Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Write to file is not formatting properly
1 回表示 (過去 30 日間)
古いコメントを表示
I have a code where I have some calculations being performed 4 times in a for loop. For each iteration of the for loop, I want the data saved to a column in a .asc file. Note, I am omitting much of the code before this part.
for z=1:length(NBvec)
NB=NBvec(z);
E=(hb*kf).^2/(2*meff);
tau=(pi/gv*E.*NB*a./n.*(FB./((1-G).*FC+2*kf/qs).^2)).^-1;
muBI_13a = (e*tau/meff)*1.3;
loglog(n(1,:)*10^-15,hb*muBI_13a(1,:));
muBI_13a;
length(muBI_13a)
fprintf(fileID,'%5.2f,%5.2f,%5.2f,%5.2f\r\n',muBI_13a');
%axis([1 12 1 50])
legend('1', '4', '16', '64')
box
end
fprintf(fileID,'%5.2f,%5.2f,%5.2f,%5.2f\r\n',muBI_13a');
fclose(fileID);
box
My saved file looks like below
x x x x
x x x x
x x x x x
x x x x
x x x x
x x x x x
x x x x
x x x x
x x x x
x x x x x
x
Not sure how to get it to give me all my data properly in the 4 columns, without adding an extra column every now and then, and having only one column in the last row...
0 件のコメント
回答 (1 件)
Image Analyst
2017 年 8 月 19 日
Not sure why but obviously the size of the matrix is changing from 5 to 4 to 1. Use the debugger to find out why (just like we'd have to do if we had your complete code). http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
2 件のコメント
Image Analyst
2017 年 8 月 19 日
On the first iteration, muBI_13a is a 1 by 61 vector, so since there are only 4 format specifiers in the fprintf() statement, it will keep repeating that until all 61 elements have been printed.
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!