How to split an array into individual values for passing them into a multiple input function?
Mostrar comentarios más antiguos
Dear community,
I need to pass an array as a multiple variables into an anonymous function.
I am wondering if there is a way to perform the following code in a single line:
fun = @(x1,x2,x3) whatever_function
x = [1 2 3];
y = num2cell(x);
fun(y{:})
The idea is to perform something like this:
num2cell(x){:}
But this code does not work.
The reason for that is passing an array into an anonymous function created by
matlabFunction
.
Respuestas (1)
Cris LaPierre
el 25 de Feb. de 2021
If the function has 3 input arguments, MATLAB expects each input to be separated by commas. The way I would do this is to pass in one column for each input.
fun(y{:,1},y{:,2},y{:,3})
Categorías
Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!