MATLAB – changing variable name with each iteration?

Using eval function to change variable name with each matrix.

A = randint(10000,4);

Dividing the given matrix A in to 5 equal sets in a sequential manner.

for i=1:5
    j=(2000*(i-1))+1;
    %A_size = size(A(j:j+1999,:));
    eval([‘A_’ num2str(i) ‘=’ ‘A(‘ num2str(j) ‘:’ num2str(j) ‘+1999,:);’]);
end

 

Advertisements