MATLAB Answers


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

Asked by MatlabFan
on 6 Apr 2013


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:


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 ?





No products are associated with this question.

1 Answer

Answer by per isakson
on 6 Apr 2013
 Accepted answer

With R2012a I fail to reproduce your problem. Try

    class( extractPass )
    double( extractPass )

to find out what get returns


I made a little experiment:

    >> ohe = uicontrol( 'Style', 'edit', 'max', 3,'min',1 )
    ohe =
    >> set(ohe,'String', {'abc','dfg'})

deleted the strings in the editbox interactively and

    >> str=get(ohe,'String')
    str = 
    >> isempty( char( str ) ) 
    ans =

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.

You have a < 2x1 cell> array of strings (or something else). Try this

    whos extractPass
    for ii = 1 : numel( extractPass )
        class( extractPass{ii} )
        isempty( extractPass{ii} )

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!

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!