Simulink: Class instance as output of a MATLAB function block

13 vues (au cours des 30 derniers jours)
Anna Fontana
Anna Fontana le 13 Juin 2023
Modifié(e) : Fangjun Jiang le 14 Juin 2023
Hi All!
I'm new to simulink and I'm creating a Simple Model in which I add a MATLAB Function block.
The function is:
function [my_object] = CreateMyInstance()
my_object = MyClass();
my_object.a = 1;
end
And MyClass is defined in external file MyClass.m and is the simple:
classdef MyClass < handle
properties
a
end
methods
function obj = MyClass()
obj.a = 0;
end
end
end
If I try to run the simulation I get the following error:
A top-level output parameter containing a class is not supported in MATLAB Function Block. Output parameter 'my_object' contains a class.
Can anyone help me on this issue or suggest another way to solve the problem? Is there a way to output the istance from the function ?
Thank you in advance

Réponses (1)

Fangjun Jiang
Fangjun Jiang le 14 Juin 2023
Modifié(e) : Fangjun Jiang le 14 Juin 2023
If involving object and class, use the MATLAB System block, although, you can't output an "object". You can utilize the methods and properties, but the output needs to be some types of data.

Catégories

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

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by