フィルターのクリア

Number and alphabet

3 ビュー (過去 30 日間)
john
john 2012 年 5 月 7 日
Hi,
I have edittext and pushbutton.
If I write with "sym(' ')" for example a1 or R2 or alfa34...matlab works good. If I write any text in this format a1 into edittext, then I want to enable pushbutton.
But if the firts is number for example 1a or 45R or 89gama, then matlab generate error. So if I write any text in this format 2a into edittext, then I want to disable pushbutton.
Please, how Can I do this?
Thank you
  3 件のコメント
john
john 2012 年 5 月 7 日
Yes, I understand...but I need avoid, that somebody will insert variables which start from a number.
John D'Errico
John D'Errico 2012 年 5 月 7 日
Use a regular expression to test for this event.

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

回答 (1 件)

Titus Edelhofer
Titus Edelhofer 2012 年 5 月 7 日
Hi,
you can use isvarname for this purpose, something like
str = get(handles.edit1, 'string');
if isvarname(str))
set(handles.pushbutton1, 'enable', 'on')
else
set(handles.pushbutton1, 'enable', 'off')
end
Titus
  9 件のコメント
john
john 2012 年 5 月 17 日
I think, that command "~isvarname(string) || isnan(str2double(string))" doesn't work. Do you have any Idea?
,
,
if ~isvarname(string) || isnan(str2double(string))
set(handles.pushbutton1,'enable','off');
else
set(handles.pushbutton1,'enable','on');
end;
Walter Roberson
Walter Roberson 2012 年 5 月 17 日
What difficulties are you encountering?

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by