Can I call a class function from Simulink?
25 ビュー (過去 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.
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!