Method invocation using dot notation error

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

Accepted Answer

Matt J
Matt J on 29 Sep 2021
Edited: Matt J on 29 Sep 2021
The superclass defines a subsref method. Therefore, you must make an overloaded subsref method in your subclass mss to enable dot indexing.
  1 Comment
Luuk Poort
Luuk Poort on 29 Sep 2021
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

Sign in to comment.

More Answers (0)

Categories

Find more on Create System Objects in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!