How can I use plus operation with more than 2 array

1 Ansicht (letzte 30 Tage)
Wongnarin Kompor
Wongnarin Kompor am 1 Feb. 2016
Kommentiert: David Young am 3 Feb. 2016
I try to plus with many array. For example plus(A,B,C,D,...Z) with A = [1,2,3:4,1,2] B = [3,5,6,:5,6,7] and so on and I've got this message
"??? Error using ==> plus Too many input arguments."
How can I solve this? Thank you in advance for your answer
  2 Kommentare
Stephen23
Stephen23 am 1 Feb. 2016
plus is a binary operator, the documentation shows this and does not state otherwise. You will need to perform it multiple times.
Wongnarin Kompor
Wongnarin Kompor am 2 Feb. 2016
Thank you for suggest me

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 1 Feb. 2016
There is no way of doing that in MATLAB: you need to do a series of binary plus operations, A+B+C+....
You may wish to consider:
nd = ndims(A);
sum( cat(nd+1, A, B, C, .... Z), nd+1 )
Note: this code will not work if any of the elements are scalars, unless they are all scalars. All of the matrices need to be the same size for this code to work.
  2 Kommentare
Wongnarin Kompor
Wongnarin Kompor am 2 Feb. 2016
Thank you very much
David Young
David Young am 3 Feb. 2016
If the arrays are large, this makes extravagant use of memory.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

David Young
David Young am 1 Feb. 2016
Either use
A + B + C + D + Z
or
plus(A, plus(B, plus(C, plus(D, Z))))

Kategorien

Mehr zu Parallel Computing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by