I have a loop like this:
for i=1:no
%some calculations
fid = fopen('c:\\out.txt','wt');
%write something to the file
fclose(fid);
end
I want data to be written to different files like this:
i=1
, data is written to out1.txt
i=2
, data is written to out2.txt
i=3
, data is written to out3.txt
Doing 'out'+ i
does not work. How can this be done?
Yet another option would be the function SPRINTF:
fid = fopen(sprintf('c:\\out%d.txt',i),'wt');
filename = strcat('out', int2str(i), '.txt');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With