Problem with empty text input GUI

조회 수: 2 (최근 30일)
Armando Assini
Armando Assini 2016년 2월 4일
댓글: Armando Assini 2016년 2월 4일
Hey guys!
I recently started using the GUI option and I´ve been having problems with text inputs, whatever I do I cannot seem to find out wheter it´s empty or not...
It should be as simple as:
handles.Xmin=get(hObject,'String');
if isempty(handles.Xmin)
%commands
end
Right? But that way I keep getting something like 6.00072 as answer.
More precisely, this code goes inside an okbutton_pressfcn, so, it should check if my value is empty whenever I press OK.
Any suggestions?
Thanks already!
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 2월 4일
Next time it happens, to debug use
get(handles.Xmin)
and look at the properties to figure out what handle it is that has somehow been stored in the String property.
Armando Assini
Armando Assini 2016년 2월 4일
Ingrid, it´s right! I just renamed the editText to Xmin.
And debugging made me realize my handle wouldn't work just by using the okbutton_pressfcn because it wouldn't really get anything from the UI, so the value I got was a random handle number!
I fixed it by initializing all handles on 'ZERO' and using that as an error. For now it´s working haha.
Thanks all!

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

채택된 답변

Joseph Cheng
Joseph Cheng 2016년 2월 4일
편집: Joseph Cheng 2016년 2월 4일
odd because if i use this snippet of code:
figure,
txtbox = uicontrol('style','edit');
txt = get(txtbox,'string');
length(txt)
isempty(txt)
isempty works for me. you could also try using length() to see how many characters are in it as spaces would look like an "empty" matrix or come out as not empty
i do not know the reason why you're having an issue but if you look up 6 here http://ascii.cl/ you'll see what 6 represensts.
  댓글 수: 2
Ingrid
Ingrid 2016년 2월 4일
the answer that he gets is 6.00072 which is clearly a handle value so that's why I am assuming he is not using the right hObject
Joseph Cheng
Joseph Cheng 2016년 2월 4일
i wouldn't say it is clearly a handle value, i'm giving the person the benefit of the doubt and assuming they know what they tagged the uicontrol with. if you perform char(6.00072) it returns '' which is an empty value. But as like most questions like this using the debug tool will probably solve it by basically figuring out where their values are coming from.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by