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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

GUI edit text box values not getting updated

Asked by srikanth on 2 Apr 2013

Hi friends i am working with matlab gui. Problem is string values are not getting updated. please check the sample code below

if true
  function pushbutton_Callback(hObject, eventdata, handles)
if    strcmp(get(handles.pushbutton,'String'),'START')
      set(handles.pushbutton,'String','STOP')
     %some code
      while(strcmp(get(handles.pushbutton,'String'),'STOP'))
          disp('Entered while loop')
          %some code 
                  Input1=sscanf(InputTemp, '%d')  
                  set(handles.Textbox1, 'String', Input1)
                  end
          [ Control ] = Controller( Input1 ) %function that will give control signal %depending on input temperature
                    if(Control=='0001')
                        set(handles.Textbox2, 'String','some text' )
                    else
                        set(handles.Textbox2, 'String','some text1' )
                    end
            %some code
        end        
else        
        set(handles.pushbutton,'String','START')    
end

end

If i hit 'pushbutton' string "start" should be changed to "stop" but that is not happening. But if that is the case process should not enter while loop. But it is entering while loop and running every thing inside continuously as required(receiving values and sending desired values through serial port). Only problem i am getting in while loop is both edit text boxes 'Textbox1' and 'Textbox2' are not displaying required values. If i am terminating the process(Ctrl+C) then the final value of temperature and control strings are getting displayed. I am unable to find any error with the code. Please help me out with this.

Thanks in advance.

0 Comments

srikanth

Products

No products are associated with this question.

1 Answer

Answer by Jan Simon on 2 Apr 2013
Edited by Jan Simon on 2 Apr 2013
Accepted answer

Give the button a chance to update by calling:

drawnow

Comparing strings by the == operator is prone to errors, so prefer STRCMP:

% if (Control=='0001')  % Better:
if strcmp(Control, '0001')

1 Comment

srikanth on 2 Apr 2013

thanks now it is working.

Jan Simon

Contact us