0

I have matlab scripts(m files) now I have to 1. integrate them to a GUI using the guide tool. there is an initialization file say 'file1' and dependent files 'file2','file3' etc. have to push this into GUI. 2. The figure/image plotting is causing me issues i.e. I have 2 different axes plots and have to push images from say file2 to axes1 and file3 to axes2 but it is plotting on the same axes time and again.

Note: file2 and file3 have two different calls from gui using the pushbutton but file2 is dependent on file1 and file3 on file1 and file2 Need help to proceed

Thanks in advance

  • You are probably relying on the current figure being the figure you want to plot to. I presume you are calling figure at some point in the initialization file and assuming this will be the current figure in other files. You'll need to store figure handles in the workspace and use these figure handles in the dependant files when plotting. You'll probably need to change to using functions instead of scripts at some stage to make this work nicely. – grantnz Jun 10 '13 at 08:47
  • how to do the same with a figure? i mean in one of the scripts a figure is updated in a for loop this figure also has to be plotted nad updated at runtime in the gui.... – user2470148 Jun 10 '13 at 09:30
  • See the help: `axes(H) makes the axis with handle H current.` - also if the axes are in different figures. – bdecaf Jun 10 '13 at 13:07

1 Answers1

0

Set-up figures in initialisation script

hFigures(1) = figure;
plot((1:10).^2)

hFigures(2) = figure;
plot(1:100);

Plot to a specific figure from another script

set(0,'CurrentFigure', hFigures(1));
hold on
plot(ones(10,1)*50,'r')

If you need to plot from within the GUI, you'll need to first get access to the hFigures variable (from the workspace). You can do this with:

 hFigures = evalin('base','hFigures')

As I said in the comment, it would be better it you could change your scripts to functions rather than relying on workspace variables and had the initialisation function return the figure handles and the update function take figure handle(s) as parameters but I don't know much about your code base so this may not be easy to do at this stage.

grantnz
  • 7,322
  • 1
  • 31
  • 38