how to get string for empty Edit Text in Matlab GUI ?

Hi,
I inserted an Edit Text in a Matlab GUI, and I would like to perform some actions when nothing is in the Edit Text (Edit Text empty). I have the following:
extractPass=get(handles.inputPassword_txt,'string');
The problem is that, when the Edit Text is empty, isempty(extractPass)= 0. I was expecting isempty(extractPass)=1 when the Edit Text is empty.
What do I need to write to know when the Edit Text is empty ?
Thanks.

 Réponse acceptée

With R2012a I fail to reproduce your problem. Try
class( extractPass )
double( extractPass )
to find out what get returns

7 commentaires

MatlabFan
MatlabFan le 6 Avr 2013
Modifié(e) : MatlabFan le 6 Avr 2013
Thank you for assisting me isakon.
>>class(extractPass) ans = cell
What I am trying to achieve is to perform some actions when the edit text is empty. Apparently, when I create an edit text box and insert nothing into then
isempty(get(handles.inputPassword_txt,'string'))
returns a value of 0. It is weird.
What does
size(extractPass)
show? I'm going to guess it shows 1 x 1, and that extractPass{1,1} is going to be empty.
I think cell indicates that it is a multi-line edit box. Check the on-line help.
Try
size( extractPass )
isempty( char( extractPass ) )
MatlabFan
MatlabFan le 6 Avr 2013
Modifié(e) : MatlabFan le 6 Avr 2013
isempty( char( extractPass ) )
Error using char
Cell elements must be character arrays.
size( extractPass )
ans=
2 x 1
extractPass{1,1}
ans=
0
per isakson
per isakson le 6 Avr 2013
Modifié(e) : per isakson le 6 Avr 2013
I made a little experiment:
>> ohe = uicontrol( 'Style', 'edit', 'max', 3,'min',1 )
ohe =
0.0023
>> set(ohe,'String', {'abc','dfg'})
deleted the strings in the editbox interactively and
>> str=get(ohe,'String')
str =
{''}
>> isempty( char( str ) )
ans =
1
or better
isempty( [str{:}] )
the char doesn't hurt if str is character, but if str not a scalar it might. Matlab is sometimes tiresome!
Thank you very much for your help Isakon. I appreciate that. It still doesn't solve the problem though.
per isakson
per isakson le 7 Avr 2013
Modifié(e) : per isakson le 7 Avr 2013
You have a < 2x1 cell> array of strings (or something else). Try this
extractPass{1}
extractPass{2}
whos extractPass
for ii = 1 : numel( extractPass )
class( extractPass{ii} )
isempty( extractPass{ii} )
end
or use the variable editor to find out what is in the cells.
Do you have a squeezed scroll bar to the right end of the edit box?
If nothing helps restart Matlab!

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by