MATLAB: How to open two files instead of one, using this “for” loop

forfor looploopswhile loop

Hi,
My current "for" loop opens one file only and writes three lines in it using permurations, for c, s and t.
I need to modify this code to make it ONLY read the values in "s", since the values in "c" and "t" are always zeros. Also, I need to make the loop opens a second file and record each "j".
For example: The first printed file will have:
0 1 0
0 2 0
0 3 0
0 4 0
0 5 0
The second file will have: set case 1, set case 2, set case 3, set case 4, set case 5.
I tried to modify the code, but it does not seem to be working.
close all; clc; clear all;
c= [0 0 0 0 0];
s = [1 2 3 4 5];
t= [0 0 0 0 0];
for i=1:5;
for= j=1:5;
for m=1:5;
line1 =['' num2str(c(i)) ';'];
line2 =['' num2str(s(j)) ';'];
line3 =['' num2str(t(m)) ';'];
fid= fopen('Pulse.tcl','w'); % First file
fprintf(fid,'%s\n',line1);
fprintf(fid,'%s\n',line2);
fprintf(fid,'%s\n',line3);
fid=fclose('all');
line1=['set case 'numer2str(j)',''];
fid=fopen('Case.tcl','w'); % Second file
fprintf(fid,'%s\n',line3);
fid=fclose('all');
end
end
end

Best Answer

I was thinking going much simpler. Again, unless there is a reason you are making it so complicated, why not just do something like this:
c= [0 0 0 0 0];
s = [1 2 3 4 5];
t= [0 0 0 0 0];
M = [c' s' t'];
dlmwrite('Pulse.tcl',M,'delimiter',' ');
fid = fopen('Case.tcl','w+');
for j = 1:5
fprintf(fid, 'set case %d\n',j);
end
fclose(fid);