Pushbutton function to plot

4 views (last 30 days)
dlyman
dlyman on 14 Jul 2015
Answered: Brendan Hamm on 14 Jul 2015
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.

Answers (1)

Brendan Hamm
Brendan Hamm on 14 Jul 2015
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,...);

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!