Transfer graphics handle between methods in Level-2 MATLAB S-Function

조회 수: 2 (최근 30일)
In the Start method of a Level-2 MATLAB S-Function I create a graphics object e.g. a surf. In the Update method I want to manipulate the object e.g. add an offset to its ZData. How can the Update method access the object created in the Start method? I tried to (mis)use the Dwork vector to transfer the graphics handle of the surf from Start to Update, but obviously Dwork does not accept graphics handles any more (since they became objects in 2011).
I know that I can use global variables (bad style) or findobj (slow) in the Update method to access the surf. Is there a better way?

채택된 답변

Joerg Buchholz
Joerg Buchholz 2017년 1월 5일
The Mathworks answered:
Using DWork indeed does not work since this does not accept all datatypes, the UserData field of your block can contain any datatype which you want however. This field can be accessed by using get_param and set_param on the BlockHandle:
function setup(block)
s = surf(peaks);
set_param(block.BlockHandle,'UserData',s);
function Update(block)
s = get_param(block.BlockHandle,'UserData');
s.ZData = s.ZData * 2;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by