adding matrices inside cell array
Mostra commenti meno recenti
how does one add all of the matrices stores in a cell array?
1 Commento
Oleg Komarov
il 10 Feb 2011
Be more specific, what do you intend by add the matrices? (take the sum of each single matrix, sum elementwise all the matrixes, all the single matrix sums are added together?
Risposta accettata
Più risposte (1)
Oleg Komarov
il 10 Feb 2011
An example:
% Create dummy input
c = {[1 2; 3 4], [3 3; 1 1]}
c =
[2x2 double] [2x2 double]
% Elementwise sum across matrices (only if ALL matrices have same size)
sum(cat(3,c{:}),3)
ans =
4 5
4 5
% Total sum of each matrix
cellfun(@(x)sum(x(:)),c,'un',0)
ans =
[10] [8]
% Grand sum
c = cellfun(@(x) x(:),c,'un',0);
sum(cat(1,c{:}))
ans =
18
Oleg
1 Commento
Mariacarla Memeo
il 30 Set 2011
Excuse me Oleg,
can you explain your solution for the first case(sum of each element of matrices), because I have to sum 72 matrices [25x25] placed in a cell array [72x1] and I've no idea to how set your solution in my example. Please.
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!