MATLAB: How to change this code

charcter

Hi, can anyone help me how to change DATA1 to DATA2, DATA3,…..DATA21 automatically in the code below ? Thanks in advance,
for i=1:length( *DATA1*)
siga2 *DATA1*_cor(i,1)= *DATA1*(i,8)-(((4*t*Em)/D)*( *DATA1*(i,1)+( *DATA1*(i,2)/3)));
end

Best Answer

Define DATA as a cell array of length N, rather than variables DATA_1, ... DATA_N.
Here is a brief example:
NCELLS = 3;
DATA = cell(NCELLS,1);
% Fill the cells with some mock data as an example
for nc = 1:NCELLS
DATA{nc} = rand(7,5);
end
s = zeros(NCELLS,1);
% Do a sample operation
for nc = 1:NCELLS
for i=1:length(DATA{nc})
s(i) = mean(DATA{nc}(i,1));
end
end