Clear Filters
Clear Filters

Can I call a class function from Simulink?

29 views (last 30 days)
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.

Accepted Answer

Jacob Halbrooks
Jacob Halbrooks on 20 Jun 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.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!