Use of fopen in for loop
4 views (last 30 days)
Show older comments
I want to create data file in matlab. for single array i have written:
fid = fopen('uN.dat','w');
fprintf(fid,'%6.8f\n',reshape(a,20000,1)');
fclose(fid) ;
suppose a is a 128x20000 matrix and i want to create data file for each of the row. that means my I want 128 data file each consisting of 1x20000 matrix and their name will be like uN1,uN2....uN128.
then certainly I need a for loop. how to do that?
0 Comments
Answers (1)
dpb
on 24 Mar 2015
While this was written with the idea of reading files, it's perfectly valid for writing as well. You'll just use
fprintf(fid,'%6.8f\n',a(:,idx))
in the loop to select a given column each pass.
0 Comments
See Also
Categories
Find more on Low-Level File I/O in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!