string data type is not a class?

1 view (last 30 days)
Matt J
Matt J on 14 Jul 2021
Commented: Rik on 15 Jul 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 Comment
Rik
Rik on 14 Jul 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.

Sign in to comment.

Accepted Answer

Rik
Rik on 14 Jul 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 Comments
Steven Lord
Steven Lord on 15 Jul 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 on 15 Jul 2021
It makes sense to solve the ambiguity this way, but I still think it would merit a remark in the doc.

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!