how to use nested functions in simulink

hello all,
I am using matlab function of simulink ,in my function some where needs the data from another function and when it gete this data it sends it to another one like below example
how can I implement this ?
thanks alot
function A = main function(a1,a2)
firsi_var =odeset(@func1,....)
second var= ode15s(@func2, first_var,...)
end

4 commentaires

Walter Roberson
Walter Roberson le 11 Juil 2019
Have your MATLAB Function Block call mainfunction
There are restrictions against using anonymous functions directly in MATLAB Function Block, but you can call a function that uses them.
You might possibly need to initialize first_var before assigning to it. Sometimes in Simulink it is easier to just create the structure directly instead of returning it from a function.
thank you Walter ,my main function is in the matlab function and for the second function when I call another function it gives this error:
Function handles cannot be passed to extrinsic functions.
this part of my code in simulink is:
options = odeset('Events',[value_ejection,isterminal_ejection,direction_ejection]);
dvdt_ejection = [lvdt ; rvdt ;pudt ; padt; aodt ; vcdt ; avdt; pvdt; mtdt ; tcdt];
[t_e,v_e,TE_e,VE_e] = ode15s(@volume_ejection,tspan,v0,options);
the volume_ ejection function's outputs are:lvdt,rvdt ,pudt ,padt ,aodt ,_vcdt ,avdt ,pvdt, mtdt ,tcdt
Hetvi Patel
Hetvi Patel le 21 Mar 2020
hello hamid ,i am facing the same problem.Did you find a solution for it?
[Tv,ZV] = ode15s (fcn, t_v, ZV0, solver_options);
solver_options = odeset ('Mass', TM_Matrix, 'MassSingular', 'yes');
fcn = @(t,T) Thermomodel_fcnDAE(T, L_Matrix, Pv_Vektor, T_ref_Pv, T_K);
[Tv,ZV] = ode15s (fcn, t_v, ZV0, solver_options);
function dT = Thermomodel_fcnDAE(T, L_Matrix, Pv_Vektor, T_ref_Pv, T_K)
global count_fcn
global Pv_out
count_fcn = count_fcn + 1;
Pv_out = Pv_Vektor;
Pv_out(1) = Pv_Vektor(1)*(1+3.9/1000*(T(1)-T_ref_Pv));
Pv_out(2) = Pv_Vektor(2)*(1+3.9/1000*(T(2)-T_ref_Pv));
dT = L_Matrix * [T; T_K] + Pv_out;
end
THESE ARE MY EQUATIONS

Connectez-vous pour commenter.

Réponses (0)

Question posée :

le 11 Juil 2019

Commenté :

le 21 Mar 2020

Community Treasure Hunt

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

Start Hunting!

Translated by