How to open an axes object inside a GUI ?

I am using GUIDE and plot a graph in axes object created within the GUI. I would like to have a way where I can open that axes in a figure window outside the GUI. (best if I can just double click to open !!) Is there any such way to do so ?

 Respuesta aceptada

Evan
Evan el 29 de Jul. de 2013
Editada: Evan el 29 de Jul. de 2013

1 voto

If you're asking if this sort of functionality is available without doing your own coding when interacting with axes in figure windows, I do not believe it is.
One option you could look into is always plotting the data in a separate figure window and being able to dock or undock that "sub-figure" in your main figure. I think that would require extensive work, though, and personally I don't think it would be as slick or ascetically pleasing as the double-click idea that you mentioned.
Another, probably more appealing solution: If you save all the plotted data in the handles structure during your plotting function, you could just run the same plotting function but output to a figure on the activation of a pushbutton or mouse click. If you want this to happen when the user clicks within your axes, look into the WindowButtonDownFcn. If you want to require a double-click for the figure to open, look into using a timer object withing the button down function as discussed here.

3 comentarios

Nitun
Nitun el 29 de Jul. de 2013
Hi Evan , Thanks for your reply.
Let me tell you what exactly I want to do with the GUI. I will have an axes inside GUI where a modeling plot will appear based on selection from a popupmenu.
Whenever a particular plot interests user, that current plot can be viewed by either clicking or by a pushbutton.(as you have suggested) It is important to get the plot in the axes and whenever i need , i can open in a new figure window.
I am very new to Matlab and especially using GUI. If you could show me an example or link me some code , it will be really helpful.
Evan
Evan el 29 de Jul. de 2013
Editada: Evan el 29 de Jul. de 2013
Since you're new to Matlab and GUIs, it might be easiest to first set up functionality for the user to open up the graph in a new window using a pushbutton. This way, you can make sure you have the basic operations down without having to dig too deep into the many functions available to your figure window.
Later, if you want to learn how modify the functionality so that the window is opened on a double-click, you can do so without having too scrap much of your old code.
Here's a simple example for plotting your data in a separate figure window using a pushbutton:
function myCalculations_Callbacks(hObject,eventdata,handles)
% Here is an example callback that you would find in your GUI's mfile.
% This would correspond to whatever routine generates the data in your graph.
% We'll make some random data, then save it to the handles structure.
% This allows us to use it later in another function.
x = [0:pi/16:2*pi];
y = sin(x);
plotRoutine(x,y,handles.myAxes) %send data to our custom plotting routine
myTitle = 'Sin(x)';
myXLabel = 'x';
myYLabel = 'y';
title(myTitle);
xlabel(myXLabel);
ylabel(myYLabel);
handles.x = x; %put all the data you want to keep in handles
handles.y = y;
handles.myTitle = myTitle;
handles.myXLabel = myXLabel;
handles.myYLabel = myYLabel;
guidata(hObject,handles)
Next, you'll need to add code to the callback for your pushbutton so that it will make an identical plot in a new figure window:
function myPushbutton_Callback(hObject,handles,eventdata)
plotRoutine(handles.x,handles.y)
title(handles.myTitle);
xlabel(handles.myXLabel);
ylabel(handles.myYLabel);
Finally, since both functions call the same plotRoutine, you'll need to create it in your mfile. To dinstinguish between plotting to an embedded axes and one in a new figure window, you could base it on how many arguments are passed in. if x,y data and a handles to an axes object is passed in, the function will assume its in your main GUI. if only x,y data is passed in, it'll plot to a new figure window:
function plotRoutine(varargin)
x = varargin{1};
y = varargin{2};
if narargin > 2
ax = varargin{3};
plot(ax,x,y)
else
figure;
plot(gca,x,y)
end
pr
pr el 7 de Dic. de 2013
@ Evan Excellent!!! You forgot to include ''narargin = length(varargin);'' in the function ''plotRouting''. and thankyou for the solution.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Preguntada:

el 29 de Jul. de 2013

Comentada:

pr
el 7 de Dic. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by