how to sum rows within cell arrays?

5 visualizzazioni (ultimi 30 giorni)
lucksBi
lucksBi il 4 Gen 2018
Commentato: lucksBi il 4 Gen 2018
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 Commenti
lucksBi
lucksBi il 4 Gen 2018
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 il 4 Gen 2018
Check my answer.

Accedi per commentare.

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by