How to loop through all the input of a function

35 visualizaciones (últimos 30 días)
QY
QY el 14 de Feb. de 2019
Editada: Adam Danz el 27 de Abr. de 2021
I have a simulink matlab function which has many inputs.
output = fcn(input1, input2, ... inputx )
Is there a way to iterate through every input on by one inside the function?
I know if the function take input as varargin I can use varargin{i} to loop through. But what if the input to the function is fixed?
  4 comentarios
Umair Ali Shah
Umair Ali Shah el 27 de Abr. de 2021
I have same issue function cannot evaluate array and manual input is not a solution.
Jonas
Jonas el 27 de Abr. de 2021
aaand we could use the who() function at the start of the function together with the eval() function to work on the variables. but i would not suggest that

Iniciar sesión para comentar.

Respuestas (1)

Adam Danz
Adam Danz el 27 de Abr. de 2021
Editada: Adam Danz el 27 de Abr. de 2021
As mentioned in the comments by Matt J and myself under this question, the only two recommended solutions to looping over input variables is
  1. pack your inputs into a single array variable
  2. use varargin which automatically packs all inputs into a cell array.
Then you can loop over all elements of the array.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by