How to read To Workspace block signal value to App Designer ?

12 ビュー (過去 30 日間)
AK
AK 2024 年 3 月 28 日
編集済み: AK 2024 年 4 月 1 日 4:28
Hi Everyone
I know I am asking the question for which answer exists somewhere , but I am new to app designer and I have simple requirement.
In mymodel.slx has "To Workspace1" output block.
In GUI callback to read model output , I am reading using get_param.
Signal1 = get_param('mymodel.slx/To Workspace1','VariableName');
As Signal1 is timeseries data. I want to extract last value to use further.
valueout1 = Signal1.Data(end,:); % Reads the value as last timestamp
At above line I am getting error as "Struct contents reference from a non-struct array object."
In command window code line valueout1 = Signal1.Data(end,:);
works as expected.
valueout1 is expected to get numeric value from 0-9. which I will use in switch case to displa\y some string in Text Box.
***********************
Request your inputs . I am trying to get simplest way to read model output and use it to display on App designer GUI.

採用された回答

Fangjun Jiang
Fangjun Jiang 2024 年 3 月 28 日
編集済み: Fangjun Jiang 2024 年 3 月 28 日
Likely it is caused by this
Signal1 = get_param('mymodel.slx/To Workspace1','VariableName') gives you a char array containing the variable name, like
Signal1='MyOutput'.
In the base workspace, variable named 'MyOutput' does exist but you need to do
MyVariable=evalin('base',Signal1);
Then you can do, MyVariable.Data(end,:)
  4 件のコメント
Fangjun Jiang
Fangjun Jiang 2024 年 3 月 29 日
To Workspace data is written when the simulation is finished. To do what you want, see Block Run-Time Objects
AK
AK 2024 年 4 月 1 日 4:27
編集済み: AK 2024 年 4 月 1 日 4:28
I was also exploring on same thing..I will take this approach. Thanks for your response.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by