Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Write to file is not formatting properly
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Image Analyst
le 19 Août 2017
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 commentaires
Image Analyst
le 19 Août 2017
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.
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!