string data type is not a class?

1 vue (au cours des 30 derniers jours)
Matt J
Matt J le 14 Juil 2021
Commenté : Rik le 15 Juil 2021
I would expect the following to pull up a list of methods for the string data type, but it does not:
methods("1")
No class 1.
Is there any rationale to this behavior?
  1 commentaire
Rik
Rik le 14 Juil 2021
s={string([])};cellfun('isempty',s),cellfun(@isempty,s)
ans = logical
0
ans = logical
1
This implies the isempty function is overloaded for strings (which is what the cellfun doc warns about for the legacy syntax), but this fact is not reflected in the values methods returns.
Why all these implementation details are hidden is a mystery to me.

Connectez-vous pour commenter.

Réponse acceptée

Rik
Rik le 14 Juil 2021
help methods
METHODS Display class method names. METHODS CLASSNAME displays the names of the methods for the class with the name CLASSNAME. Use the functional form of METHODS, such as METHODS(S), when CLASSNAME is a string scalar. METHODS(OBJECT) displays the names of the methods for the class of OBJECT. M = METHODS(...) returns the method names in a cell array of character vectors. If CLASSNAME represents a MATLAB or Java class, then only public methods are returned, including those inherited from base classes. METHODS differs from WHAT in that the methods from all method directories are reported together, and METHODS removes all duplicate method names from the result list. METHODS CLASSNAME -full displays a full description of the methods in the class, including inheritance information and, for MATLAB and Java methods, method attributes and signatures. Duplicate method names with different signatures are not removed. M = METHODS( ..., '-full') returns the full method descriptions in a cell array of character vectors. The word METHODS is also used in a MATLAB class definition to denote the start of a methods definition block. Examples: %Example 1: %Retrieve the names of the public methods of class 'memmapfile' %and capture the result in a cell array of character vectors. methodnames = methods('memmapfile'); %Example 2: %Construct a java.lang.String instance and display the names of %the public methods of that instance. s = java.lang.String; methods(s); See also METHODSVIEW, PROPERTIES, EVENTS, CLASSDEF, WHAT, WHICH. Documentation for methods doc methods Other functions named methods icdevice/methods imaqdevice/methods icgroup/methods iviconfigurationstore/methods icinterface/methods serial/methods imaqchild/methods
This suggests that you can't use the methods(object) syntax for char and string inputs.
methods('1')
No class 1.
methods(class("1"))
Methods for class string: append contains eq extractAfter gt issorted lt pad reverse startsWith cellstr count erase extractBefore insertAfter join matches plus sort strip char double eraseBetween extractBetween insertBefore le ne replace split strlength compose endsWith extract ge ismissing lower or replaceBetween splitlines upper
  7 commentaires
Steven Lord
Steven Lord le 15 Juil 2021
There are a couple entries in the Release Notes related to the interaction between string arrays and the ismethod function, but I don't see any about string arrays and the methods function. I could have overlooked one, though, since searching the Release Notes for the word "method" or "methods" finds a lot of hits.
Rik
Rik le 15 Juil 2021
It makes sense to solve the ambiguity this way, but I still think it would merit a remark in the doc.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by