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!