How does one count the characters in an array?

How do I obtain an arrays character count?
Eg. Value = 1111
I want the character count output to be 4

1 commentaire

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

value='1111'
out=numel(value)

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

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
Jay le 13 Avr 2016
The handle is to an edit box which I will use for a date output (thus Value > 0).
The date will not necessarily be of the current date but can be past, present or future (used in astronomic tables).
The structure of the input is to be DDMMYYYY.
I have written if statements that will throw an error if the inputted value is alphabetical.
Once I have a way to reference and further analyse the number of characters, I plan to have other (respective) errors shown in the listbox relating to the where the user went wrong with their editbox input.
I also plan for the values in the editbox to be portioned in the output to list:
'On the first two numbers day' 'of the second two numbers month' 'of the last 4 numbers year'
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

Community Treasure Hunt

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

Start Hunting!

Translated by