How to count of numbers in matlab GUI program?

1 回表示 (過去 30 日間)
95
95 2020 年 4 月 13 日
回答済み: Rajani Mishra 2020 年 4 月 16 日
the first Edit Field “Input Numbers” is a ‘Text’ Edit Field, and the other two below are ‘Numeric’ Edit Fields.
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 4 月 14 日
Is this to be done through optical character recognition? Is it something that has to be passed the handle of a figure and it has to figure out the number of visible numbers?
... You missed the '3' in the title "Q3" by the way.

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

回答 (1 件)

Rajani Mishra
Rajani Mishra 2020 年 4 月 16 日
You can try following steps to find the count of numbers in the Edit field:
  • Retrieve the string entered from the Edit Field
x = get(handles.editField,'String');
if isempty(x)
fprintf('Error: Enter Text first\n');
else
% Code for spliting the string on delimiters and returning the length of the string after
% (explained below).
end
  • Split the string on the delimiters, in your case - ',' and '<space>'
x2 = strsplit(x,{'',','});
  • Remaining string will only have numbers hence length of this string array will be the count of numbers (Given that in the "Input Numbers" text field user only inputs numbers)
Hope this helps!

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by