Use of fopen in for loop

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?

Answers (1)

dpb
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.

Categories

Asked:

on 23 Mar 2015

Answered:

dpb
on 24 Mar 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!