From: Ahmed on 14 Jul 2010 12:58 i want to make GUI using uicontrol that adds , subtracts , multiplies , divides two numbers , but it give me ??? The class "handles" is undefined. Perhaps Java is not running. Error in ==> process>pushbutton_callback at 34 first_number=str2double(get(handles.first_number_tag,'string')); ??? Error while evaluating uicontrol Callback ------------------------------------------------------------------------------- function process uicontrol('style','edit','string',... 'Enter first number','tag','first_number_tag',... 'position',[281,200,110,50]); uicontrol('style','popup','string',... {'select process','+','-','*','/'},'tag','process_tag',... 'position',[281,166,110,20]); uicontrol('style','edit','string',... 'Enter second number','tag','second_number_tag',... 'position',[280,99,110,50]); uicontrol('style','pushbutton','string',... 'press here to get the answer','callback',@pushbutton_callback,... 'position',[30,28,200,50]); uicontrol('style','edit','string','0','tag','result_tag',... 'position',[281,28,110,50]); function pushbutton_callback(h,e,varargin) first_number=str2double(get(handles.first_number_tag,'string')); process=get(handles.process_tag,'vaule'); second_number=str2double(get(handles.second_number_tag,'string')); switch process case 2 , result=first_number+second_number; case 3 , result=first_number-second_number; case 4 , result=first_number*second_number; case 5 , result=first_number/second_number; end result_str=num2str(result); set(result1_header,'string',result_str) end end
From: Frédéric Bergeron on 14 Jul 2010 15:16 "Ahmed " <worldmember(a)yahoo.com> wrote in message <i1kqas$ccv$1(a)fred.mathworks.com>... > i want to make GUI using uicontrol that adds , subtracts , multiplies , divides two numbers , but it give me > ??? The class "handles" is undefined. > Perhaps Java is not running. > Error in ==> process>pushbutton_callback at 34 > first_number=str2double(get(handles.first_number_tag,'string')); > ??? Error while evaluating uicontrol Callback > ------------------------------------------------------------------------------- > function process > > uicontrol('style','edit','string',... > 'Enter first number','tag','first_number_tag',... > 'position',[281,200,110,50]); > > uicontrol('style','popup','string',... > {'select process','+','-','*','/'},'tag','process_tag',... > 'position',[281,166,110,20]); > > uicontrol('style','edit','string',... > 'Enter second number','tag','second_number_tag',... > 'position',[280,99,110,50]); > > uicontrol('style','pushbutton','string',... > 'press here to get the answer','callback',@pushbutton_callback,... > 'position',[30,28,200,50]); > > uicontrol('style','edit','string','0','tag','result_tag',... > 'position',[281,28,110,50]); > > function pushbutton_callback(h,e,varargin) > first_number=str2double(get(handles.first_number_tag,'string')); > process=get(handles.process_tag,'vaule'); > second_number=str2double(get(handles.second_number_tag,'string')); > > switch process > case 2 , result=first_number+second_number; > case 3 , result=first_number-second_number; > case 4 , result=first_number*second_number; > case 5 , result=first_number/second_number; > end > result_str=num2str(result); > set(result1_header,'string',result_str) > end > end Hey, From what I see, you may want to define handles for your uicontrols. You should write handles.first_number_tag=uicontrol(...), or use handles=guihandles(...). Since you have all your tag properties setted, guihandles should works without a lot of difficulties. help guihandles Bye
From: Ahmed on 14 Jul 2010 16:46 i changed the code , there are no errors but the result is always NaN ------------------------------------------------------------------------------------------------ function myprocess first_number_handle=uicontrol('style','edit','string',... 'Enter first number','tag','first_number_tag',... 'position',[281,200,110,50]); process_handle=uicontrol('style','popup','string',... {'select process','+','-','*','/'},'tag','process_tag',... 'position',[281,166,110,20]); second_number_handle=uicontrol('style','edit','string',... 'Enter second number','tag','second_number_tag',... 'position',[280,99,110,50]); uicontrol('style','pushbutton','string',... 'press here to get the answer','callback',@pushbutton_callback,... 'position',[30,28,200,50]); result_handle=uicontrol('style','edit','string','0','tag',... 'result_tag','position',[281,28,110,50]); function pushbutton_callback(h,e) first_number=str2double(guidata(first_number_handle)); process=get(process_handle,'value'); second_number=str2double(guidata(second_number_handle)); switch process case 2 , result=first_number+second_number; case 3 , result=first_number-second_number; case 4 , result=first_number*second_number; case 5 , result=first_number/second_number; end result_str=num2str(result); set(result_handle,'string',result_str) end end
From: Ahmed on 14 Jul 2010 17:05 i changed the code and it worked -------------------------------------------------------------- function myprocess first_number_handle=uicontrol('style','edit','string',... 'Enter first number','tag','first_number_tag',... 'position',[281,200,110,50]); process_handle=uicontrol('style','popup','string',... {'select process','+','-','*','/'},'tag','process_tag',... 'position',[281,166,110,20]); second_number_handle=uicontrol('style','edit','string',... 'Enter second number','tag','second_number_tag',... 'position',[280,99,110,50]); uicontrol('style','pushbutton','string',... 'press here to get the answer','callback',@pushbutton_callback,... 'position',[30,28,200,50]); result_handle=uicontrol('style','edit','string','0','tag',... 'result_tag','position',[281,28,110,50]); function pushbutton_callback(h,e) first_number=str2double(get(first_number_handle,'string')); process=get(process_handle,'value'); second_number=str2double(get(second_number_handle,'string')); switch process case 2 , result=first_number+second_number; case 3 , result=first_number-second_number; case 4 , result=first_number*second_number; case 5 , result=first_number/second_number; end result_str=num2str(result); set(result_handle,'string',result_str) end end ---------------------------------------------------------------------------------- thank youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
From: Ahmed on 14 Jul 2010 17:10 i changed the code and it worked -------------------------------------------------------------- function myprocess first_number_handle=uicontrol('style','edit','string',... 'Enter first number','tag','first_number_tag',... 'position',[281,200,110,50]); process_handle=uicontrol('style','popup','string',... {'select process','+','-','*','/'},'tag','process_tag',... 'position',[281,166,110,20]); second_number_handle=uicontrol('style','edit','string',... 'Enter second number','tag','second_number_tag',... 'position',[280,99,110,50]); uicontrol('style','pushbutton','string',... 'press here to get the answer','callback',@pushbutton_callback,... 'position',[30,28,200,50]); result_handle=uicontrol('style','edit','string','0','tag',... 'result_tag','position',[281,28,110,50]); function pushbutton_callback(h,e) first_number=str2double(get(first_number_handle,'string')); process=get(process_handle,'value'); second_number=str2double(get(second_number_handle,'string')); switch process case 2 , result=first_number+second_number; case 3 , result=first_number-second_number; case 4 , result=first_number*second_number; case 5 , result=first_number/second_number; end result_str=num2str(result); set(result_handle,'string',result_str) end end ---------------------------------------------------------------------------------- thank youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
|
Pages: 1 Prev: Image processing/selection help Next: Copy formatted Excel lines from Matlab prompt |