How to add matrices in a function with varying input arguments
4 views (last 30 days)
Show older comments
I have a function: myfunction(varargin), where the varargin are matrices. I want this function to add all of the matrices I input. Hows the best way of doing this?
0 Comments
Accepted Answer
James Tursa
on 16 Jul 2014
Do you mean simply adding up all of the varargin individual inputs, like this?
if( nargin )
matrix_sum = varargin{1};
for k=2:nargin
matrix_sum = matrix_sum + varargin{k};
end
end
0 Comments
More Answers (1)
See Also
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!