How does one count the characters in an array?
Ältere Kommentare anzeigen
How do I obtain an arrays character count?
Eg. Value = 1111
I want the character count output to be 4
1 Kommentar
Walter Roberson
am 11 Apr. 2016
Is that
Value = 1111
or is it
Value = '1111'
If it is numeric, then how do you want to process negative numbers, and how do you want to process numbers with fractional part, and how do you want to process numbers that would typically be expressed in scientific notation?
Akzeptierte Antwort
Weitere Antworten (2)
Andrei Bobrov
am 11 Apr. 2016
Bearbeitet: Andrei Bobrov
am 11 Apr. 2016
If your Value is numeric type, then:
out = floor(log10(Value)+1);
if Value is char type then:
out = numel(Value - '0');
1 Kommentar
Walter Roberson
am 11 Apr. 2016
This does not work for numeric Value < 1
4 Kommentare
Walter Roberson
am 11 Apr. 2016
You have to have a handle to something . What is it a handle to ?
If your response is that it is a graphics handle, especially a uicontrol, then none of the defined graphics objects use Value to hold strings: in each case, Value is numeric or empty. Strings can be in String properties or in Data properties (uipanel) or in UserData properties, or in properties such as xticklabel.
Jay
am 13 Apr. 2016
Walter Roberson
am 13 Apr. 2016
Edit boxes do not have a Value. Edit boxes have a String.
S = get(handles.edit1, 'String');
length(S)
Jay
am 17 Apr. 2016
Kategorien
Mehr zu Dates and Time finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!