How update some variables each time tha I'am calling simulink from Matlab funtion

7 ビュー (過去 30 日間)
viyils Sangregorio
viyils Sangregorio 2021 年 8 月 24 日
編集済み: Paul 2021 年 8 月 31 日
I have a funtion which recibe some variables, in thus funtion I'am calling a simulink block and getting some datas...
The problem is I need this Var1 Var2 in Simulink block ? What can i do ? To use this vars values in my simulink ??
function [Out] = Funtion (Var1, Var2 ....)
simout = sim('Simulinkblock');
Yx = simout.yout{1}.Values.Data;
Cx = Yx(end);
end

回答 (2 件)

Paul
Paul 2021 年 8 月 31 日
編集済み: Paul 2021 年 8 月 31 日
Try using a Simulink.SimulationInput object. Change the code to:
function [Out] = Funtion (Var1, Var2 ....)
in = Simulink.SimulationInput('Simulinkblock')
in = in.setVariable('D',Var1); % to set the value of D. Repeat for others as needed.
simout = sim(in);
% simout = sim('Simulinkblock');
Yx = simout.yout{1}.Values.Data;
Cx = Yx(end);
end

Rishabh Singh
Rishabh Singh 2021 年 8 月 30 日
As per my understanding you want to pass the input to your Simulink Model through as an input to the function.
This issue can be resolved if you have root inport in your Simulink Model by using setExternalInput (Refer to example code for understanding).
Other approach could be loading data from Workspace, for that you can refer to From Workspace or using MAT file to provide input.
Hope this helps.

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by