Optional Function input arguments

6 次查看(过去 30 天)
I am writing a function and basically it does a set of command on the inputted matrices, How can i specify that the user can enter any number of matrices as inputs and the code will perform the command on all of them. So if three matrices are inputted then the code runs for the 3 and if 20 are inputted the commands are done for all 20. I hope i explained my problem well enough
  1 个评论
Ahmed Abdulla
Ahmed Abdulla 2020-6-7
for example i would like to get the highest 3 numbers by considered all data from the inputted matrices but i dont know how many matrices the user is going to input.

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2020-6-7
编辑:Matt J 2020-6-7
You would use varargin,
function theFunction(varargin)
for i=1:numel(varargin)
matrix=varargin{i};
...
end
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by