How can I use plus operation with more than 2 array

2 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 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.

请先登录,再进行评论。

采纳的回答

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.

更多回答(1 个)

David Young
David Young 2016-2-1
Either use
A + B + C + D + Z
or
plus(A, plus(B, plus(C, plus(D, Z))))

类别

Help CenterFile Exchange 中查找有关 Parallel Computing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by