how to sum rows within cell arrays?

조회 수: 11 (최근 30일)
lucksBi
lucksBi 2018년 1월 4일
댓글: lucksBi 2018년 1월 4일
Hi all
how to sum rows within cell arrays?
array1 = {[4,3.3,2.5,0.71];[3.4,2,1,0.3]}
Result may look like this:
result = {[10.51];[6.7]}
  댓글 수: 2
lucksBi
lucksBi 2018년 1월 4일
I have tried using sum
for x=1:8
result{x,1} = sum(array1{x,1});
end
But it gives following error:
Cell contents assignment to a non-cell array object.
Birdman
Birdman 2018년 1월 4일
Check my answer.

댓글을 달려면 로그인하십시오.

채택된 답변

Birdman
Birdman 2018년 1월 4일
for i=1:length(array1)
result{i}=sum(array1{i},2);
end
  댓글 수: 1
lucksBi
lucksBi 2018년 1월 4일
Yes problem solved. I have to clear result array and then apply this code.
Thanks alot.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by