how do i sequentially name a variable on each loop in matlab

You can create a string with the desired variable names using sprintf and the loop counter variable, and then use the eval function to create the variables with those names. Here's an example code:

main.m
for i = 1:10
    varName = sprintf('myVar%d', i);
    value = i * 2; % Or any other value that you want to assign to the variable
    eval(sprintf('%s = %d', varName, value));
end
180 chars
6 lines

This code will create 10 variables named myVar1, myVar2, ... myVar10, with values 2, 4, ..., 20, respectively.

related categories

gistlibby LogSnag