フィルターのクリア

How does one count the characters in an array?

5 ビュー (過去 30 日間)
Jay
Jay 2016 年 4 月 11 日
コメント済み: Jay 2016 年 4 月 17 日
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)
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 4 月 12 日
(It turns out this is not what Justin wanted)

サインインしてコメントする。

その他の回答 (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');
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 4 月 11 日
This does not work for numeric Value < 1

サインインしてコメントする。


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)
Jay
Jay 2016 年 4 月 17 日
Thankyou Walter.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by