How can I keep track of Handle Graphic objects in my MATLAB S-Function Block?

조회 수: 3 (최근 30일)
I have a custom MATLAB S-Function block that is used to plot data while the simulation is running. How can I keep track of the handle graphic objects that are created while this block executes?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2021년 3월 4일
편집: MathWorks Support Team 2021년 3월 4일
There are two main options that can be used to keep track of handle graphic objects:
1. Use tags and findobj.
This method works well if you will only ever need a single instance of the block in the model. If you may need multiple instances of the block in the model it may not work well as the value of the tag property is generally hard coded.
a. When the handle graphic object is created set the 'tag' property to a unique ID such 'myLine'
b. In later block methods when the object needs to be used use findobj in order to get a handle to the object>> h = findobj(0,'tag','myLine') 
2. Use block UserData
This method works well if you may need multiple instances of the block in the model. This is because the block UserData is block instance specific, meaning that each instance of the block could easily have a reference to their own handle graphic object.
For a fully worked out example of this workflow please see the attached Simulink model and S-Function code.
a. When the handle graphic object is created store a copy of the object, or a structure that contains the object along with other data, in the block UserData>> ud = struct('h',figure)>> set_param(block,'UserData',ud);b. In later block methods when the object needs to be used get_param to get the object >> ud = get_param(block,'UserData');
Note that prior to R2014b MATLAB treated handles of handle graphic objects as variables of the double data type instead of objects. As a result the handle to the objects could also be stored in the Dwork vector of the S-Function. For more information on using Dwork vectors please see:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by