Effacer les filtres
Effacer les filtres

How does one count the characters in an array?

5 vues (au cours des 30 derniers jours)
Jay
Jay le 11 Avr 2016
Commenté : Jay le 17 Avr 2016
How do I obtain an arrays character count?
Eg. Value = 1111
I want the character count output to be 4
  1 commentaire
Walter Roberson
Walter Roberson le 11 Avr 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?

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 11 Avr 2016
value='1111'
out=numel(value)
  1 commentaire
Walter Roberson
Walter Roberson le 12 Avr 2016
(It turns out this is not what Justin wanted)

Connectez-vous pour commenter.

Plus de réponses (2)

Andrei Bobrov
Andrei Bobrov le 11 Avr 2016
Modifié(e) : Andrei Bobrov le 11 Avr 2016
If your Value is numeric type, then:
out = floor(log10(Value)+1);
if Value is char type then:
out = numel(Value - '0');
  1 commentaire
Walter Roberson
Walter Roberson le 11 Avr 2016
This does not work for numeric Value < 1

Connectez-vous pour commenter.


Jay
Jay le 11 Avr 2016
Modifié(e) : Jay le 11 Avr 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 commentaires
Walter Roberson
Walter Roberson le 13 Avr 2016
Edit boxes do not have a Value. Edit boxes have a String.
S = get(handles.edit1, 'String');
length(S)
Jay
Jay le 17 Avr 2016
Thankyou Walter.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by