1

I currently have a .m file that creates a ton of figures. It currently outputs those figures into a powerpoint, one slide per figure, but I would rather something more user friendly. I would like to use an app with app designer for this but I cannot figure out how to make figures appear inside of a GUI.

My goal: have a drop down on the left side of the GUI that lets you choose a figure title, and then that figure will appear in the large axes on the right side of the GUI.

The code currently closes each figure after it is saved, but that can be changed if necessary.

Can anyone help me with this? Is this even possible?

Kenny G
  • 13
  • 3
  • If each figure only has one `axes`, you could use `copyobj` to copy the content of the axes in a stored figure (see [this](https://stackoverflow.com/questions/28921113/matlab-openfig-to-existing-figure) post). If the created figures have subplots, this becomes a bit more tricky, since you'd have to initialize the same subplots as in the original figure. Another option could be to save all figures as images (e.g. png or jpg), and do an `imload` and `imshow` based on the selection in the dropdown menu. Unfortunately, that way you cannot interact with the figure anymore. – rinkert Oct 01 '19 at 16:26
  • You could plot everything in your figures inside a `uipanel`, then load the figure and re-parent the panel with something like `myPanel.Parent = appContainer` – Wolfie Oct 01 '19 at 16:30
  • Both of these answers would work well, thanks! Since my code is already built and the GUI is not, and since all the figures are a single axes, I believe Rinkert's answer matches what I need best. However if I were to start from scratch I would probably use Wolfie's solution (this would require many changes especially since I plan to leave in the code that writes the figures to powerpoint). I will implement this and let you know if it works. – Kenny G Oct 01 '19 at 17:56
  • @rinkert Could you better explain how to implement your first idea? I cannot get it to work. It seems to be exactly what I need but I keep getting errors with copyobj. – Kenny G Oct 01 '19 at 21:58

1 Answers1

0

Not a complete answer, but some pointers on how to load created .fig files, and copy the axes to an uipanel.

First create some figure:

f1 = figure();
subplot(211)
imagesc(rand(100));
subplot(212)
plot(rand(100,1))

saveas(f1, 'figure1.fig')

And then load this figure in your GUI. A very simple example GUI:

fig = uifigure;
fig.Position = [100 100 800 600]
pan1 = uipanel(fig, 'Title', 'Figure', 'Position',[0 0 600 600])
pan2 = uipanel(fig, 'Title', 'Select Figure', 'Position',[600 0 200 600])

f_new = openfig('figure1.fig', 'invisible'); % load 'invisible' so it doesn't popup
ax_to_copy = f_new.Children;  % works even with subplots!

% and copy the loaded axes to the uipanel:
copyobj(ax_to_copy, pan1)

Result:

enter image description here enter image description here

rinkert
  • 6,593
  • 2
  • 12
  • 31
  • Thank you for your help! This does work in app designer like I was hoping as well. At first I didn't think it would work, but then I realized that I was trying to write the figure into a pre-defined axes within the app instead of into a panel. I don't quite understand why that was an issue, but changing app.UIAxes to app.RightPanel made it work. – Kenny G Oct 02 '19 at 18:05