Method invocation using dot notation error

3 ビュー (過去 30 日間)
Luuk Poort
Luuk Poort 2021 年 9 月 29 日
コメント済み: Luuk Poort 2021 年 9 月 29 日
Hello,
I have extended the built-in class mechss to add some additional methods.
In the simplest sense, see the class definition below.
classdef mss < mechss
%MSS Extension of MECHSS class
methods
function obj = mss(varargin)
% Constructor method
obj = obj@mechss(varargin{:});
end
function showM(obj)
% Simple method displaying the first block of the mass matrix
disp(full(obj.M(1:10,1:10)));
end
end
end
Now, if I want to call the method showM of an instance of an mss object, documentation says I can use both the dot and function notation. The function notation functions correctly, but the dot notation gives me an error, as shown below.
msys = mss(M,K,B,F,G,D); % Creating an instance of the mss object, using arbitrary second order system matrices
showM(msys); % Functions correctly
msys.showM(); % Gives the error shown below
Error using InputOutputModel/subsref (line 43)
No property of the class "mss" matches the identifier "showM". Use PROPERTIES to get the list of properties for this class.
It thus shows an error in the subsref function. Further study shows that specifically line 29 of the subsref funciton (see below) throws the error that the number of output arguments is too large, although it only gives one output when executed without any output.
% Line 27-29 from the subsref function, located in
% C:\Program Files\MATLAB\R2020b\toolbox\shared\controllib\engine\@InputOutputModel\subsref
Struct(1).subs = ltipack.matchProperty(Struct(1).subs,...
ltipack.allprops(M),class(M));
result = builtin('subsref',M,Struct(1));
Using the dot notation using a very simple super- and subclass does work, so it seems an issue with the InputOutputModel class.
Is it possible to fix the dot notation functionality?
Thank you.
PS: I am using MATLAB 2020b and the control system toolbox for the mechss functionality.

採用された回答

Matt J
Matt J 2021 年 9 月 29 日
編集済み: Matt J 2021 年 9 月 29 日
The superclass defines a subsref method. Therefore, you must make an overloaded subsref method in your subclass mss to enable dot indexing.
  1 件のコメント
Luuk Poort
Luuk Poort 2021 年 9 月 29 日
Hi Matt,
Thank you for your very quick response!
Adding a very simple subsref method, as seen below, indeed solved my issues.
function varargout = subsref(obj, S)
[varargout{1:nargout}] = builtin('subsref',obj,S);
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreate System Objects についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by