string data type is not a class?

조회 수: 1 (최근 30일)
Matt J
Matt J 2021년 7월 14일
댓글: Rik 2021년 7월 15일
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
Rik
Rik 2021년 7월 14일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by