simulink mask callback adding variables to workspace

조회 수: 8 (최근 30일)
Amish Rughoonundon
Amish Rughoonundon 2016년 3월 1일
댓글: Sebastian Castro 2016년 3월 2일
Hi, I have a subsystem with a mask and a callback function based on what option the user chooses in the mask dialogue. I set some variables in the callback function as below
rev = 1
The variable appears in the matlab workspace. Is there a way to keep the variable from appearing in the workspace but still be able to use it in the callback function code? Thanks, Amish

채택된 답변

Sebastian Castro
Sebastian Castro 2016년 3월 2일
편집: Sebastian Castro 2016년 3월 2일
You can take all that initialization code and move it from a block callback to the "Initialization" tab of the Mask Editor. The variables created will belong only to the masked block's workspace, so they cannot be tampered with in the base workspace.
- Sebastian
  댓글 수: 2
Amish Rughoonundon
Amish Rughoonundon 2016년 3월 2일
cool that works. I am now officially puzzled as to when to use the callback code and when to use the initialization code. I read the documentation but it's unclear why anybody would use callbacks at all
Sebastian Castro
Sebastian Castro 2016년 3월 2일
Well, the callbacks work for any block -- whether it is a masked subsystem or not.
With a masked subsystem, you get the advantage of having a local block workspace, which lends itself out for self-contained initialization code.
On the other hand, block callbacks give you control of other events besides initialization. There's a whole list of them including copy, paste, open (double-click), etc. so there's more freedom to insert code snippets at key instances if you need to.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Author Block Masks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by