Can I call a class function from Simulink?
조회 수: 16 (최근 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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Create System Objects에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!