Function for symbolic expression with only some variable among all variables

5 ビュー (過去 30 日間)
Marco
Marco 2013 年 1 月 22 日
Hi,
I have this symbolic expression:
J =
[ - a2*sin(t1 + t2) - a1*sin(t1), -a2*sin(t1 + t2)]
[ a2*cos(t1 + t2) + a1*cos(t1), a2*cos(t1 + t2)]
[ 0, 0]
[ 0, 0]
[ 0, 0]
[ 1, 1]
where symvar are:
[ a1, a2, t1, t2]
I saw that I can convert this symbolic expression by matlabFunction command but variables/function-input must be [ a1, a2, t1, t2].
Because I want to put resultant function into a Interpreted MATLAB Function block, how can I assign only t2 as "input" and the others like mask-parameters ? There is a way to convert J to a matlab function with only t2 as input?

回答 (1 件)

Shashank Prasanna
Shashank Prasanna 2013 年 1 月 23 日
You can use anonymous function to do that. However make sure that the other 3 variables a1 a2 t2 are also defined in the function other wise it will error out.
>> Jfun = matlabFunction(J)
Jfun =
@(a1,a2,t1,t2)reshape([-a2.*sin(t1+t2)-a1.*sin(t1),a2.*cos(t1+t2)+a1.*cos(t1),0.0,0.0,0.0,1.0,-a2.*sin(t1+t2),a2.*cos(t1+t2),0.0,0.0,0.0,1.0],[6,2])
>> Jfunt2 = @(t2)Jfun
Jfunt2 =
@(t2)Jfun
This was you can call Jfunt2 with only t2 as input arguments, but make sure the other 3 variables are defined someone above.
  2 件のコメント
Walter Roberson
Walter Roberson 2013 年 1 月 23 日
You would need
Jfunt2 = @(t2)Jfun(a1, a2, t1, t2)
where a1, a2, t1 were defined in scope when the anonymous function was defined.
Walter Roberson
Walter Roberson 2013 年 1 月 23 日
I am concerned here about whether Simulink MATLAB functions are permitted to use anonymous functions (or function handles). I do not recall that as being one of the permitted datatypes in such functions. I might be getting confused on terminology, though, about which Simulink MATLAB functions are executed in MATLAB as a whole and which ones have to conform to the embedded function requirements.

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

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by