Summing matrices in cell array

I have a cell array A that is 9x1 with 9 cells that are all 1x38. I am trying to sum A (sum elements of the 9 cells). I have tried cell2mat,cellfun, sum(cat), and sum, but I keep getting errors with those. Any help is appreciated! Thanks!!

Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 10 Jun. 2016
Bearbeitet: Azzi Abdelmalek am 10 Jun. 2016

0 Stimmen

A={[1 2 3];[4 5 6];[7 8 9]}
out=cellfun(@sum,A)
If A is like this
A={{1 2 3};{4 5 6};{7 8 9}}
out=cellfun(@(x) sum(x{1}),A)

1 Kommentar

Jennifer
Jennifer am 10 Jun. 2016
Bearbeitet: Jennifer am 10 Jun. 2016
What is x? Here's what I've tried so far: inside A are the 9 cells that are 1x38.
for i=1:38
A=[rnLadp;rnLfie;rnLhaa;rnLhfe;rnLhie;rnLkfe;rnLpap;rnLpie;rnLpud];
C=cell2mat({sum(cat(2,A{:,i}),2)}
end
With this code, I am getting C 38 times but I want to make a cell or matrix or array that has all 38 values from the loop. Advice??

Melden Sie sich an, um zu kommentieren.

Produkte

Gefragt:

am 10 Jun. 2016

Bearbeitet:

am 10 Jun. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by