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!