Can I call a class function from Simulink?
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Evert Trollip
el 20 de Jun. de 2014
Respondida: Jacob Halbrooks
el 20 de Jun. de 2014
I created a superclass with the name Aircraft, which has various properties to describe an Aircraft such as: the states, controllers, linear dynamics etc.
classdef Aircraft < handle
properties
AtmosphericProperties;
Attributes;
States;
TrimSettings;
LinearDynamics;
Controllers;
end
...
end
This class also has a few method functions which is used in Simulink. In other words, after creating a model aircraft in Simulink, I used a MATLAB Function block (Simulink/User-Defined Functions/MATLAB Fcn) and called a function in the Aircraft Class:
Aircraft.myFunction(u)
The function in the class would then look something like this:
function output = myFunction(obj, input)
...
...
output = ...
end
Now, at the moment Simulink has not given me any problems but I would like to know if something like this is a good or bad idea? I've done some research on the web and found that people have been a bit negative about using objects and classes in Simulink. Yes, I struggle to send an object in Simulink, however, it seems to have no problem in calling the method of a particular class.
Any professional opinions or comments with regards to objects and classes in MATLAB and Simulink?
Thanks in advance.
0 comentarios
Respuesta aceptada
Jacob Halbrooks
el 20 de Jun. de 2014
I'd suggest you take a look at the MATLAB System block, which is designed to support System objects in Simulink. System objects are MATLAB classes that extend "matlab.System" and then implement a few algorithm methods (most importantly, stepImpl). Here are a couple of resources so you can learn more:
Using the MATLAB System block is a well supported means of using a class in Simulink, but your current approach of using objects in a MATLAB Function block should also work.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Create System Objects en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!