Saving binary file in Matlab in a loop? -


consider matrix a in matlab of dimension mxn , suppose want save binary file test.dat using

file_id = fopen('test.dat', 'w'); fwrite(file_id, a, 'float32'); fclose(file_id); 

now suppose created within loop h=1:100: how can assign binary files names test1.dat, test2.dat,...,test100.dat? in other words want , question related step 2):

%for h=1:h     %1)do creates     %2) save using     %file_id = fopen('test'h'.dat', 'w'); %clearly wrong     %fwrite(file_id, a, 'float32');      %fclose(file_id); %end 

in code posted, line:

%file_id = fopen('test'h'.dat', 'w'); %clearly wrong 

should read:

file_id = fopen(strcat('test',num2str(h),'.dat'),'w'); 

and should trick nicely.


Comments