MATLAB: Dynamic Loop with for

MATLAB and Simulink Student Suite

Dynamic Loop

Best Answer

N = [6 44 ; 170 179 ; 198 203] ;
iwant = cell(size(N,1),1) ;
for i = 1:size(N,1)
for j = N(i,1):N(i,2)
iwant{i} = [iwant{i} j] ; % just demo to show the variables after loop
end
end
iwant{1}
iwant{2}
iwant{3}
Related Question