How to split an array into individual values for passing them into a multiple input function?
Afficher commentaires plus anciens
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
.
Réponses (1)
Cris LaPierre
le 25 Fév 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})
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!