MATLAB: How to do loop in the Workspace

loopmeanworkspace

I have four matrixes c1 c2 c3 c4 (each matrix is 45×9)in the workspace. I need to calculate the mean for each row in each matrix.
The code I tried does not work:
c = {c1, c2, c3, c4};
for j = 1:4
mean_c(j) = mean(c{j},2);
end

Best Answer

Method One: for loop:
c = {rand(45,9), rand(45,9), rand(45,9), rand(45,9)};
d = cell(size(c));
for k = 1:numel(c)
d{k} = mean(c{k},2);
end
Method Two: cellfun:
d = cellfun(@(m)mean(m,2),c,'UniformOutput',false);
Convert to numeric by simply using cell2mat:
>> cell2mat(d)
ans =
0.49524 0.40269 0.65561 0.47278
0.59244 0.52532 0.41187 0.42431
0.34457 0.58936 0.54098 0.55274
0.52958 0.62364 0.50265 0.52148
0.70699 0.65555 0.58959 0.48702
0.38250 0.34663 0.54874 0.48712
0.59373 0.44404 0.62564 0.39276
0.48016 0.59843 0.57385 0.48644
0.49235 0.52315 0.52946 0.53855
0.51168 0.69419 0.46208 0.35696
0.53927 0.46378 0.48168 0.49156
etc