Assume I have a matrices C1,C2 as follows:
C1 = nx1 cell each cell is [5x5 double].
C2 = nx1 cell each cell is [5x5 double].
How to calculate C3 as:
C3{1,1} = C1{1,1}+C2{1,1};
C3{2,1} = C1{2,1}+C2{2,1};
.
.
C3{n,1} = C1{n,1}+C2{n,1};
using cellfun or any other method without looping

 Akzeptierte Antwort

dpb
dpb am 28 Dez. 2015

1 Stimme

cellfun(@plus,A,B,'uni',0)
cell2mat(A)+cell2mat(B)

2 Kommentare

Alnazer
Alnazer am 28 Dez. 2015
Just to clarify; your answer provides two ways to solve the problem;
C3 = cellfun(@plus,A,B,'uni',0);
Result in C3 a cell array, while
C3 = cell2mat(A)+cell2mat(B);
Result in C3 as array type double.
am l right??
dpb
dpb am 28 Dez. 2015
Yes altho the latter is easily converted simply by enclosing in the curlies...
C3 = {cell2mat(A)+cell2mat(B)};
Which might have a performance advantage I've no idea...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sean de Wolski
Sean de Wolski am 28 Dez. 2015

2 Stimmen

If you have the neural networks toolbox:
gadd(A,B)

1 Kommentar

command line documentation
help gadd
doc gadd
See also gsubtract, gmultiply, gdivide, gnegate.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 28 Dez. 2015

Kommentiert:

am 29 Dez. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by