필터 지우기
필터 지우기

Guide- coma

조회 수: 2 (최근 30일)
john
john 2012년 3월 20일
Hi, can you help me please? I have problem with comma ",". I need this:
If I write number into edittext with coma for example 4,3 or 34,4534 or 2342,44 , then I need to write for example into statictext "error". . . else into statictext "ok".
It is possible?

채택된 답변

Daniel Shub
Daniel Shub 2012년 3월 20일
Generally we like to see that you have put effort into trying to solve your problem. It looks like you have been trying things here: http://www.mathworks.com/matlabcentral/answers/32252-field-text-number and that this is not exactly an overlapping question ...
I start by defining a function iscomma
function iscomma(src, h)
if strfind(get(src, 'string'), ',')
set(h, 'string', 'error');
else
set(h, 'string', 'ok');
end
Then I create two uicontrols and set the callback of the edit box to iscomma
h1 = uicontrol('style', 'edit');
h2 = uicontrol('style', 'text', 'units', 'normalized', 'position', [0.5, 0.5, 0.5, 0.5]);
set(h1, 'Callback', @(src, evt)iscomma(src, h2))
  댓글 수: 1
john
john 2012년 3월 20일
Thank you .
I made some change
str = get(handles.edit,'String')
if strfind(str, ',')
set(handles.text, 'String','error');
else
set(handles.text, 'String','ok');
end;

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Dr. Seis
Dr. Seis 2012년 3월 20일
Yes. Every time the user types something and then hits enter, or tab, or clicks somewhere else in the GUI, etc. the callback function associated with your edittext will execute and you can place a set there to change the static text to "error" or "ok" depending on whether the string you get from the edittext has a comma in it.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by