Method invocation using dot notation error

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Methods 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by