How to initialize instance of class in Simulink Global Workspace?

조회 수: 3 (최근 30일)
Roop
Roop 2024년 7월 1일
댓글: Fangjun Jiang 2024년 7월 1일
Hello,
I am aiming to create an object (instance of class) in the Simulink Global Workspace via code in the Preload Fcn Callback.
This simulink model is using a Matlab Function block to input the parameters of an object to an S-Funciton block that is tied to a larger external simulation, and then the output of this simulation is passed back to another Matlab Function block that re-initializes the data with the results, and repeats until finished. Initially, I had used Interpreted Matlab Function blocks to pass this data back and forth but I am now forced to switch out of them and decided upon Matlab function blocks. I have made all the underlying code code-generation compatible, but I am having trouble intializing in object via the global workspace in Simulink.
In my preload function callback, I simply just write:
var_name = ObjClass();
I am then aiming to call methods/functions to manipulate the properties of this object in a Matlab Function block. For instance, in my initial Matlab Function block (which has no inputs), the code is like:
function output = fcn()
output = var_name.func_name();
end
However, whenever I run the simulation, I am getting the erro that var_name.func_name() is an undefined function or variable.
Can't seem to figure out why the instance of class is not being created in the preload function as the Simulink is unchanged from successful use with Interpreted Matlab function blocks. Is there some sort of difference underlying the Matlab Function block that I am missing? Global Declarations?
Thanks!

채택된 답변

Fangjun Jiang
Fangjun Jiang 2024년 7월 1일
  댓글 수: 2
Roop
Roop 2024년 7월 1일
편집: Roop 2024년 7월 1일
With the MATLAB System block, are you not assigning the instance of ObjClass() to a "property" of the System class? Can you treat this property like an object and call methods with it? Is the syntax changed? I had tried this a while ago and given up on it due to this issue.
Fangjun Jiang
Fangjun Jiang 2024년 7월 1일
What object/class are you working on?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by