can pushbutton work without a function ????
    조회 수: 3 (최근 30일)
  
       이전 댓글 표시
    
Hello guys, i'm having problems with a pushbutton. I created a pushbutton inside a figure, however i cant use a nested function or another .m file to make it work. This button should work as itself. This is the code.
button1=uicontrol(gcf,'style','pushbutton','string','Save projected points','Position', [20 140 150 40],'ButtonDownFcn','1'); %pushbutton
if ((str2double(get(button1,'string'))) == 1)
disp('u did it')    
end
however this is not working, how to call the handles of the button or mayby just detect if this was pressed???
maybe is an stupid question, but thanx anyway
댓글 수: 0
채택된 답변
  Geoff Hayes
      
      
 2014년 9월 16일
        Jules - use Callback instead of ButtonDownFcn to detect when the button has been pressed. Try something like the following
 function example_gui
    button1=uicontrol(gcf,'style','pushbutton','string',...
                     'Save projected points',          ...
                     'Position', [20 140 150 40],      ...
                     'Callback',{@buttonCallback});
    function buttonCallback(hObject,eventData)
        disp('u did it')    
    end
 end
The buttonCallback is a nested function within the main exmaple_gui code. When you run the above, and press the button, you will observe u did it written to the console.
추가 답변 (1개)
  Image Analyst
      
      
 2014년 9월 16일
        You need to define a callback function. See this http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples if you insist on "rolling your own" GUIs instead of using GUIDE.
참고 항목
카테고리
				Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
			
	제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


