Method invocation using dot notation error

6 vues (au cours des 30 derniers jours)
Luuk Poort
Luuk Poort le 29 Sep 2021
Commenté : Luuk Poort le 29 Sep 2021
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.

Réponse acceptée

Matt J
Matt J le 29 Sep 2021
Modifié(e) : Matt J le 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 commentaire
Luuk Poort
Luuk Poort le 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Methods dans Help Center et File Exchange

Tags

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by