Filter löschen
Filter löschen

How does one count the characters in an array?

5 Ansichten (letzte 30 Tage)
Jay
Jay am 11 Apr. 2016
Kommentiert: Jay am 17 Apr. 2016
How do I obtain an arrays character count?
Eg. Value = 1111
I want the character count output to be 4
  1 Kommentar
Walter Roberson
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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 11 Apr. 2016
value='1111'
out=numel(value)

Weitere Antworten (2)

Andrei Bobrov
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');

Jay
Jay am 11 Apr. 2016
Bearbeitet: Jay am 11 Apr. 2016
That does not work.
The characters are not explicitly defined as elements in an array, but rather string values in a handle.
elCount = str2num('Value') = []
  4 Kommentare
Walter Roberson
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
Jay am 17 Apr. 2016
Thankyou Walter.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by