How to set the default value for Edit Text in GUI ? If not input a number , I hope the contents auto changed to be '5'
    7 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
In the function edit1_callback(),it is writed as :
   edit1 = str2double(get(hObject,'string'));
   if isempty(edit1)
      edit1 = 5;     % when not input a number ,the contents is 5;
   end 
   handles.edit1 = edit1;
   guidata(gcbo,handles);
As a matter of fact,when I do not input a number,the edit text contents is not 5,Why?
And ,how can I set the default value of edit text??
Thank you for your attention!
0 Commenti
Risposta accettata
  Teja Muppirala
    
 il 19 Nov 2012
        STR2DOUBLE returns NaN for non-numeric data. Instead of checking for empty input using ISEMPTY, use ISNAN instead.
if isnan(edit1)
  set(handles.edit1,'string','5');
end
2 Commenti
  Arthur
      
 il 19 Nov 2012
				You forgot to store edit1. And, I think it's better to retrieve the value of handles.edit1 in the pushbutton callback. Try this:
function edit1_callback() 
edit1 = str2double(get(hObject,'string')); 
if isnan(edit1) 
set(handles.edit1,'string','5'); 
end 
function pushbutton1_callback() 
x = str2double(get(handles.edit1,'String')); 
y = x+7; 
plot(x,y,'*r');
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


