How to initialize instance of class in Simulink Global Workspace?
조회 수: 3 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
채택된 답변
Fangjun Jiang
2024년 7월 1일
If involving object/class, you might want to use MATLAB System block
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!