Question

I have a GUI(made using GUIDE) in which there is an axes on which I can draw. When I saved the gui, i have a .fig file and a .m file (whose names are start_gui.m and start_gui.fig). Now, I am trying to plot on these axes using an external M file, to which I have passed the GUI handles. This is as follows:

function cube_rotate(angle1,angle2,handles)
   gcf=start_gui.fig; %this is the name of the gui.fig file in GUIDE 
   set(gcf,'CurrentAxes',handles.cube_axes)%this allows us to plot on the GUI 
      %plot something
end 

handles.cube_axes is the name of the handle in the GUI created using guide. Inspite of passing the handles, it won't allow me to plot in the gui. It throws up an error saying:

??? Undefined variable "start_gui" or class "start_gui.fig".

start_gui.fig is the name of the GUI figure that was generated in GUIDE. How do i make it plot in the axes in start_gui.fig?

Thanks for all the help!

Était-ce utile?

La solution

You've made a few errors. The first is referring to a file name without single quotes to denote a string. The second is trying to open an existing figure by assigning it as a variable named gcf. This will just give you a variable gcf which contains the string 'start_gui.fig'.

Instead, open the figure with this command:

fH = hgload('start_gui.fig');
% Then find/assign the axes handle (assuming you only have one axes in the figure):
aH = findobj(fH,'Type','axes');
% And finally plot to the axes:
plot(aH,0:.1:2*pi,sin(0:.1:2*pi));

On a secondary note, is there a reason you're not using the M-file generated by MATLAB to carry out this functionality? By using the auto-generated M-file, you'll be able to access the handles structure rather than using findobj.

Autres conseils

The error you're getting is because of your second line: gcf=start_gui.fig;

It's looking for a variable named start_gui, which you don't have. (start_gui.fig is a filename, not a variable.)

To solve your plotting problem, take a look at this Mathworks support article.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top