Can I call a class function from Simulink?

24 次查看(过去 30 天)
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.

采纳的回答

Jacob Halbrooks
Jacob Halbrooks 2014-6-20
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 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by