MATLAB Answers


How can I use plus operation with more than 2 array

Wongnarin Kompor さんによって質問されました 2016 年 2 月 1 日
最新アクティビティ David Young
さんによって コメントされました 2016 年 2 月 3 日
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 件のコメント

Stephen Cobeldick
2016 年 2 月 1 日
plus is a binary operator, the documentation shows this and does not state otherwise. You will need to perform it multiple times.
Wongnarin Kompor 2016 年 2 月 2 日
Thank you for suggest me

サインイン to comment.


2 件の回答

Walter Roberson
回答者: Walter Roberson
2016 年 2 月 1 日

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 件のコメント

Wongnarin Kompor 2016 年 2 月 2 日
Thank you very much
David Young
2016 年 2 月 3 日
If the arrays are large, this makes extravagant use of memory.

サインイン to comment.

David Young
回答者: David Young
2016 年 2 月 1 日

Either use
A + B + C + D + Z
plus(A, plus(B, plus(C, plus(D, Z))))

  0 件のコメント

サインイン to comment.

Translated by