Sum of an arrays elements
显示 更早的评论
I have an assigntment which sounds like this:
square each element in C and determine the sum of all C's elements
How do i do this? I don't get the right result, that i am supposed to get.
采纳的回答
更多回答(1 个)
Sagar Damle
2014-2-23
Rasmus,entered matrix is wrong again! I get this fact from your description. Your matrix is - C =
10 12 15 1 1 1 0 1 1 1
7 9 13 1 8 1 0 10 7 1
1 1 1 1 1 1 0 15 13 1
Any way,I think this is what you want :
A = C.^2; Ans = sum(A(:));
For understanding purpose,see effect of A(:).
Note : For 2-dimentional matrix A, sum(sum(A)) is same as sum(A(:)).
Read help about 'sum()' in MATLAB help.
类别
在 帮助中心 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!