summation of each row in a 3D matrix

2 次查看(过去 30 天)
hello all ,
I have the bellow 3D matrix and i want to find the summation value of each row separately , anyone can help?
c(n,i,1) n=10; i=10
0 1 0 0 1 0 0 1 0 1
1 0 1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 1 0 0 0 1
0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 1 0 0

回答(1 个)

Image Analyst
Image Analyst 2022-5-8
编辑:Image Analyst 2022-5-8
Why a for loop? Why not simply use sum():
m = randi(9, 2,3,4)
sumMatrix = squeeze(sum(m, 1))'
If it's because it's your homework, then yes, we can help but not provide the complete solution for you to turn in our solution as your own, because your professor wants your work, not ours.

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by