How does one count the characters in an array?

7 次查看(过去 30 天)
How do I obtain an arrays character count?
Eg. Value = 1111
I want the character count output to be 4
  1 个评论
Walter Roberson
Walter Roberson 2016-4-11
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?

请先登录,再进行评论。

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2016-4-11
value='1111'
out=numel(value)

更多回答(2 个)

Andrei Bobrov
Andrei Bobrov 2016-4-11
编辑:Andrei Bobrov 2016-4-11
If your Value is numeric type, then:
out = floor(log10(Value)+1);
if Value is char type then:
out = numel(Value - '0');

Jay
Jay 2016-4-11
编辑:Jay 2016-4-11
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 个评论
Walter Roberson
Walter Roberson 2016-4-13
Edit boxes do not have a Value. Edit boxes have a String.
S = get(handles.edit1, 'String');
length(S)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by