Three Loops with summation
1 次查看(过去 30 天)
显示 更早的评论
Greeting,
I have matrix Z(30,70) and it repeated for 40 times each time there will be new value for each cell. This means for example Z(1,1) will have 40 different values. And the same for all cells in the matrix. My question how I can sum all 40 Z(1,1) for all values. I want to done this for each cell and save the result in matrix K(30,70)
Do I need to do three loops to accomplish that or there is another ways to do it.
Thank you in advance for all ideas.
Regards
1 个评论
Walter Roberson
2015-10-24
This sounds like the same question as your earlier http://uk.mathworks.com/matlabcentral/answers/250696-summation-of-valuse-in-nested-loops
回答(2 个)
Walter Roberson
2015-10-24
If you have a cell array Z and you want sum each of the entries, then
cellfun(@sum, Z)
if you are expecting a 30 x 70 numeric array as output, and otherwise
cellfun(@sum, Z, 'Uniform', 0)
if you are expecting a 30 x 70 cell array as output.
2 个评论
Walter Roberson
2015-10-24
for L=1:10
for i=1:20
for j=1:100
r=(Xc+Y)^(1/2);
VC=VCo*(1-(exp(-(r))));
Uf(i,j)=(((VC-Yc))/((pi)*(r)));
Vf(i,j)=((VC*r)*(Xc))/((2*pi));
Uft(i,j,L)=Uft(i,j,L)+Uf(i,j);
Vft(i,j,L)=Vft(i,j,L)+Vf(i,j);
Ufz(i,j)=(U-Uft(i,j))/U;
end;
end;
end;
Now afterwards you can use
sum(Utf,3)
sum(Vtf,3)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!