Simulink mask using workspace variables

5 ビュー (過去 30 日間)
Dinemayer Silva
Dinemayer Silva 2017 年 6 月 13 日
コメント済み: Dinemayer Silva 2017 年 6 月 13 日
In a Simulink mask I have the command disp(sprintf('(%4.2fx-%4.2f)',abs([a b]))). "a" and "b" are defined in the workspace as 2.2 and 6.8, respectively. In the command line I have the correct output (2.20x- 6.80). However, in the Simulink I ge the "???" error message. Using the preview of the mask editor, I get the message "could not evaluate MaskDisplay commands of the block xxx: Undefined function or variable 'a'."
How to correctly use variables from the workspace in Masks?
PS: I'm using Matlab R2016b.

採用された回答

Sebastian Castro
Sebastian Castro 2017 年 6 月 13 日
The mask has a separate workspace, so what you need to do is get the values from the base workspace before using them.
There is a function called evalin which will let you evaluate an expression from a separate workspace. In this case, we want to grab a and b from the BASE workspace (where you defined a and b) and stick them in the mask's workspace.
An example of code that works for the mask display callback:
myVal = evalin('base','abs([a b])');
fprintf('(%4.2fx-%4.2f)',myVal);
- Sebastian
  1 件のコメント
Dinemayer Silva
Dinemayer Silva 2017 年 6 月 13 日
Thanks Sebastian. It worked perfectly.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAuthor Block Masks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by