In Simulink, is it possible to send data to workspace in real-time using the 'ToWorkspace' block?

84 ビュー (過去 30 日間)
Hello everyone,
I have a large simulink model. In this model I calculate certain variables that are essentially [1x1] constants. For example, I analyze an electrocardiogram recording to count the number of heart cycles: num_cycles.
I would then like to use such constants like num_cycles in various other blocks like selectors and Matlab function blocks to fix the size of various variable size signals.
Now, if such constants would be defined in the workspace, I could just type num_cycles or whatever in the Simulink selector block, or in the output size of the Matlab Function's explorer. I have tried using the block "ToWorkspace" to do this. However, this block only sends data to workspace once the simulation in stopped or paused.
My question is: is there any way to send variables to the workspace immediately so that they can be accessed by future blocks as if they were workspace variables?
Thank you,
Rafael
  1 件のコメント
Paul
Paul 2020 年 10 月 25 日
I don’t think you can do this. Please post here if you find a solution.
However, the answer may be in your question. Did you read the doc on “variable size signals”?

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

採用された回答

Walter Roberson
Walter Roberson 2020 年 10 月 25 日
  9 件のコメント
Rafael Cordero
Rafael Cordero 2020 年 10 月 27 日
Ahh, I see now. I'll work with this. Thanks for all your answers!
Walter Roberson
Walter Roberson 2020 年 10 月 27 日
Thank you for your contribution, Paul!

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

その他の回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 10 月 25 日
  2 件のコメント
Rafael Cordero
Rafael Cordero 2020 年 10 月 26 日
Hi Ameer,
This is the first thing I tired.
I used a wrapped Matlab function (declaring it extrinsic to code-generation) inside a Matalb Function block to then use assignin() to pass the variables to the workspace.
Initially, I thought this had worked - the variables had been passed to the workspace correctly. However, the problem is that if I use these variables to define signal sizes or whatever, I need to have them defined at the start, while the simulink model is compiling. I could do this by predefining some dummy variable (e.g. num_cycles = 0) in Matlab, and then running the Simulink model. This variable would then be overwritten in the model with assignin( ) with the correct number of cycles. The problem is that the various blocks that make use of num_cycles will only consider the initial declaration (num_cycles = 0) which I guess is done during compilation. Future changes in this workspace variable during execution will not be reflected in the Simulink model, which will still think that num_cycles = 0.
Thanks anyhow,
Rafael
Ameer Hamza
Ameer Hamza 2020 年 10 月 26 日
I think that changing the parameters of a compiled model using values from the base workspace is not possible. You can read these values using extrensic(), but using them to changing the signal dimensions might require the re-compilation of the model.

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

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by