Use eval inside your loop:
eval(['I = length_act_', num2str(i)]);
Pro tip:
The eval
command is usually slow and inefficient, use arrays instead. In your case, it seems that each of your "length_act_i" variables is a vector on its own, so you should be employing a cell array. For instance, call it length_act
and set it like so:
length_act = {length_act_1, length_act_2, length_act_3, ...};
and then access each cell in the array using:
for i = 1:length(length_act)
I = length_act{i};
...
end
Also, it is recommended not to use "i" and "j" as names for variables.