Problem with arguments in function call - button
이전 댓글 표시
I'm creating a tabbed interface, so I can not use the GUI. I need to generate a chart, but it does not read my data in the inbox.
uicontrol('Parent', TabHandles{1,1}, ...
'Units', 'pixels', ...
'Position', [ round(PanelWidth/6.5) 6.5*ButtonHeight ...
round(PanelWidth/13) round(PanelHeight/18) ],...
'String', 'Ver', ...
'Callback', @VerCallback, ...
'Style', 'pushbutton',...
'HorizontalAlignment', 'center',...
'FontName', 'arial',...
'FontWeight', 'bold',...
'FontSize', 10);
function VerCallback(haxes2,~)
%a = get(r,'str2num');
%b = get(x,'str2num');
%plot (haxes2, 1:10, [0 a], [0 b]);
%plot(haxes2, [0 2], [0 3]);
cla;
end
답변 (1개)
When you use this syntax for a callback
'Callback', @VerCallback
The callback function will have exactly 2 input arguments, representing the source (in this case the push button handle) and some event data which is often of little use).
If you want to pass further arguments, such as an axes handle you need something more like:
'Callback', @(src,evt) VerCallback( hAxes2 )
assuming hAxes2 is defined at the point you create your uicontrol (or rather when you set its callback, which in your code is the same thing). There are other syntaxes too, but this is the one I use.
If you do want either of the source or event data arguments in your function then you can also pass these in:
'Callback', @(src,evt) VerCallback( src, evt, hAxes2 )
댓글 수: 2
Matheus Silva
2017년 2월 7일
Adam
2017년 2월 8일
Those two variable arguments to your verCallback (which you haven't shown so I have no idea what it does, but it doesn't have enough information to do what you want) are the source and the event data (the documentation details these). Anything beyond those you have to pass in yourself as you do the axes handle, unless you use a nested function.
You have named your edit boxes r and x so how can you expect a plot to plot a line involving r and x? I assume you mean str2double( r.String ), but your callback knows nothing about your uicontrols. The fact you called the variable arguments to the callback r and x doesn't matter, they are not the same r and x you have there they are just place holders for the source of the callback (which will be the pushbutton) and the event data (which is not very useful at all).
카테고리
도움말 센터 및 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!