Working with MATLAB classes in the Level-2 MATLAB S-Functions

8 ビュー (過去 30 日間)
Timur
Timur 2012 年 2 月 2 日
コメント済み: Paramjeet Panwar 2019 年 6 月 12 日
Hello,
I need an access to methods and properties of the Matlab class object (not related to axis) in the Level-2 MATLAB S-Functions. Methods and properties are used through the setup (i.e. port types) and simulation process.
Questions:
1. I need to construct an object inside an s-function. Inside what S-Function Callback Method is it better to do?
2. What are the legal ways to pass an object handle to the Lev2 S-function? Via the DialogPrm().Data?
3. What is the best way to pass object handle to the Callback Methods?
Kind regards,
Timur

採用された回答

Kaustubha Govind
Kaustubha Govind 2012 年 2 月 3 日
The ideal technique to save data in an S-function in such a way that it is available in all the callback methods is to use Work Vectors. In C-MEX S-functions, PWork vectors can be used to cache data of any type. However, the only type of work vectors available in MATLAB S-functions are DWork vectors, which can only store numeric types. The only other way I can think of sharing data between the S-function methods is to use the block UserData property. You can construct your object in the setup() method and destroy it in Terminate(). You can set/get the object on the block UserData property as follows:
set_param(block.BlockHandle, 'UserData', myobj);
myobj = get_param(block.BlockHandle, 'UserData');
Caveat: This is mostly a hack that I dreamed up - please look out for unintended consequences.
  1 件のコメント
Paramjeet Panwar
Paramjeet Panwar 2019 年 6 月 12 日
Works well for my use case! (Define and get a COM object handel from the base workspace and use it in a Matlab S-Function)

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

その他の回答 (1 件)

Craig
Craig 2014 年 4 月 28 日
More info here

Community Treasure Hunt

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

Start Hunting!

Translated by