The expression in the for
statement needs to be a row array, not a column array as in your example. The loops will exit after the first value with your code. Set a breakpoint on the saveFile.output
command to see what I mean. With a column array, par1
will not be a scalar as desired, but the whole parList1
column. With a row array, par1
will iterate through each value of parList1
as intended
Another thing is that you need to reset your inner counters (counter2
and counter2
) or your second and third dimensions will blow up larger than you expected.
The n3=1
problem is expected behavior because matfile
defines the variables with fixed number of dimensions and it will treat saveFile.output
as 2D. Once you have fixed those issues, you can solve the n3=1
problem by changing the line,
saveFile.output(counter1,counter2,counter3) = sum([par1,par2,par3]);
to
if n3==1, saveFile.output(counter1,counter2) = sum([par1,par2,par3]);
else saveFile.output(counter1,counter2,counter3) = sum([par1,par2,par3]);
end