How to split an array into individual values for passing them into a multiple input function?
이전 댓글 표시
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
.
답변 (1개)
Cris LaPierre
2021년 2월 25일
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})
카테고리
도움말 센터 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!