Effacer les filtres
Effacer les filtres

How to initialize instance of class in Simulink Global Workspace?

26 vues (au cours des 30 derniers jours)
Roop
Roop le 1 Juil 2024 à 16:15
Commenté : Fangjun Jiang le 1 Juil 2024 à 19:01
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!

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 1 Juil 2024 à 17:21
  2 commentaires
Roop
Roop le 1 Juil 2024 à 17:40
Modifié(e) : Roop le 1 Juil 2024 à 17:40
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 le 1 Juil 2024 à 19:01
What object/class are you working on?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by