Access Data in to APP DESIGNER from Simulink 'To Workspace' block.

52 ビュー (過去 30 日間)
Nagendra Vankadari
Nagendra Vankadari 2021 年 5 月 4 日
回答済み: Nagendra Vankadari 2021 年 7 月 15 日
I wanted to run a Simulink model in External mode and I am new to App Designer. To begin with I started working in Normal mode. Here is the example:
My Simulink Model: with sine wave Amplitude Variable as 'Const';
The 'to workspace is in TimeSeries format.
App Desiner Model: This has two Numeric Edit Fields(Amplitude, Duration), one Axis for plotting and start button.
Callback fn code when the start button is pushed is below:
assignin("base", 'Const',app.AmplitudeEditField.Value);
simout = sim("AppDesignSetup.slx",'StopTime', num2str(app.DurationEditField.Value));
plot(app.UIAxes,simout.SineVal.Time, simout.SineVal.Data);
I get no error and also the output graph
NOW MY PROBLEM::
when I try same way to run a external mode model, Matlab suggested me to use 'set_param' to run a model in external mode.
So, to learn about 'set_param' , I started with the same model in Normal Mode with the callback fn code :
set_param('AppDesignSetup/Sine', 'Amplitude', num2str(app.AmplitudeEditField.Value));
set_param('AppDesignSetup', 'StopTime',num2str(app.DurationEditField.Value));
set_param('AppDesignSetup', 'SimulationMode', 'normal');
set_param('AppDesignSetup', 'SimulationCommand','start');
plot(app.UIAxes, out.SineVal.Time,out.SineVal.Data);
In this the program runs perfectly until the 'plot' command. The Simulink model runs perfectly and get an 'out' struct.
But I'm unable to access it. Someone please help me with this.

回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2021 年 5 月 4 日
Use set_param() to set 'SimulationMode' and
then still run simout = sim("AppDesignSetup.slx")
so it will force the log of simulation result before plot() is run.
  2 件のコメント
Nagendra Vankadari
Nagendra Vankadari 2021 年 5 月 4 日
But if I use sim() command, then I cannot run the model in External mode.
Fangjun Jiang
Fangjun Jiang 2021 年 5 月 4 日
For external mode, you need to control it through 'connect','disconnect','stop' and then check the data.

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


Nagendra Vankadari
Nagendra Vankadari 2021 年 7 月 15 日
Accessing data from Simulink model depends on the simulation mode.
For 'normal mode':
Add a 'To Workspace' block in simulink model and use the sim command as mentioned above to access the simulink data.
For 'external mode':
It is not possible to directly access the simulink output data in external mode. To my knowledge, there are two approaches for this:
1) Event Listener Method.
2) Level 2 S-functions.
Look into these and hope this info might help.

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by