How to input vector into a function handle

i have a function handle fx1=@(x,y,z) x*2+3*y+2z;
and a vector a=[1 2 3].
is there any possible way so that i can input a into fx, without changing a into a cell arrays?
thanks in advance

5 件のコメント

Stephen23
Stephen23 2021 年 8 月 31 日
a = [1,2,3];
fx1 = @(x,y,z) x*2+3*y+2*z;
fx1(a(1),a(2),a(3))
ans = 14
Ruby Teja Kusuma
Ruby Teja Kusuma 2021 年 8 月 31 日
thankyou before, but is there are any ways so they specifically specify each element in a into function's input?
i've done this, but in array's way that is fx1(a{:}) (i've converted the a before)
Stephen23
Stephen23 2021 年 8 月 31 日
編集済み: Stephen23 2021 年 8 月 31 日
"but is there are any ways so they specifically specify each element in a into function's input?"
You are trying to generate a comma-separated list from one array. The two ways of generating a comma-separated list from one array (either from a cell array or from a structure array) are explained here:
Ruby Teja Kusuma
Ruby Teja Kusuma 2021 年 8 月 31 日
yeah this is excatly what im looking for, heavy thanks mate
Walter Roberson
Walter Roberson 2021 年 8 月 31 日
If you just happen to be generating the function handle using matlabFunction() in the Symbolic Math Toolbox, then see the 'vars' option: it is possible to arrange that the generated function takes its input from a vector instead of from from individual arguments.

サインインしてコメントする。

回答 (0 件)

カテゴリ

製品

質問済み:

2021 年 8 月 31 日

コメント済み:

2021 年 8 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by