Pushbutton function to plot

4 次查看(过去 30 天)
dlyman
dlyman 2015-7-14
I have created a GUI that takes in user input via text boxes then runs a function I created when you click the pushbutton. The last part of the function is to create a plot based on all the data and save it. I want that plot to be displayed in my axes area of my GUI. Do I need to attach the figure to some kind of global handle within the function code or is there an easier way to set this.
I have no code following the line created the axes1, and the last line of code on my pushbutton is the line that runs my function.

回答(1 个)

Brendan Hamm
Brendan Hamm 2015-7-14
The global solution is not the recommended one as this can cause problems with debugging.
What you would want to do is have the axes handle passed in as one of the arguments to the ButtonDownFcn:
function onPush(ax,callingObj,callingEvent)
% Some code here
plot(ax,...)
end
now the uicontrol for your button expects this function to take only the last 2 inputs, so you need to make an anonymous function handle which can hardcode the axes into this function.
f = @(src,evt) onPush(ax,src,evt);
It is required here that f is defined in a scope where ax is available and that the definition for the uicontrol pushbutton has access to this function handle.
bttn = uicontrol('Style','pushbutton','ButtonDownFcn',f,...);

类别

Help CenterFile Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by