MATLAB: Concatenation of few matrix with a loop

for loopmatrix manipulation

C{1} = [total1979_125_30];
C{2} = [total1980_125_30];
C{3} = [total1981_125_30];
C{4} = [total1982_125_30];
C{5} = [total1983_125_30];
…upto C{40} = [total2019_125_30];
just help me making the loop
So that I can use
A = cat(3,C{:});
M = mean(A,3);

Best Answer

It was not a good idea to create a variable name like this: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval. Always use a cell array. Since you already created these, you can use the following loop to create the cell array now.
C = {};
vals = 1979:2019;
for i = 1:numel(vals)
[~, C{i}] = evalc(sprintf('total%d_125_30', vals(i)));
end