Importing .fig with subplots into GUI

2 views (last 30 days)
R J
R J on 26 Aug 2015
Commented: R J on 26 Aug 2015
Hi,
I am trying to implement a solution posted by Bruno Luong that I found here. His solution is as follows:
% Generate a fig file
close all;
figure(1);
clf(1);
axsource=axes('Parent',1);
plot(axsource,rand(10,1));
hgsave(1,'sourcefig.fig');
close all;
% Load the fig file
h=hgload('sourcefig.fig');
set(h,'Visible','off');
tmpaxes=findobj(h,'Type','axes');
% Copy the axe
figure(2);
destaxes=subplot(2,2,1,'Parent',2)
copyobj(allchild(tmpaxes),destaxes);
% Clean up
close(h)
% Bruno
I think I have an understanding of what he is doing. What I would like to do is import a previously saved .fig file with 24 subplots (3,8,x) into a gui. I am using Bruno's example to do this by copying one subplot handle at a time and transferring to the new axes. I'm still having some issues but am working towards the solution. Am I on the right path? Any suggestions would be greatly appreciated. Thank you!
  2 Comments
R J
R J on 26 Aug 2015
Edited: R J on 26 Aug 2015
This is the change I made to Bruno's code, which seems to be working standalone. Meaning, it's been implemented outside of the gui.
% Generate a fig file
close all;
figure(1);
clf(1);
axsource=axes('Parent',1);
h = struct2handle(data.T1,0)
saveas(gcf,'sourcefig.fig')
% plot(axsource,rand(10,1));
% hgsave(1,'sourcefig.fig');
close all;
% Load the fig file
h=hgload('sourcefig.fig');
set(h,'Visible','off');
tmpaxes=findobj(h,'Type','axes');
% Copy the axe
figure(2);
for ii = 1:length(tmpaxes)
destaxes(ii)=subplot(3,8,ii,'Parent',2)
copyobj(allchild(tmpaxes(ii)),destaxes(ii));
end
% Clean up
close(h)
However, when I try to implement within my gui, I am unable to plot all subplots simultaneously in the gui figure. Here is what I am doing:
% Copy the axe
for ii = 1:length(tmpaxes)
destaxes(ii)=subplot(3,8,ii,'Parent',double(gui.PlotBox1));
copyobj(allchild(tmpaxes(ii)),destaxes(ii));
end
Having gone through it in debug mode, I see that each subplot is plotted but cleared through every iteration of the loop. "hold on;" does not seem to work. Any suggestions?
R J
R J on 26 Aug 2015
I just ended up creating the axes in the gui to handle this. That seems to be the way to do it.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!