How can I keep figures invisible when going between different figures and different subplots?
7 views (last 30 days)
Show older comments
Jennifer Davies
on 26 Oct 2016
Commented: Jennifer Davies
on 28 Mar 2017
Hi I have a script with three figures (f1, f2, and f3) that are invisible to the user, each with four subplots (sp1, sp2, sp3 and sp4). I need to call these figures at various times in the script to plot data. E.g., I first plot on f1-sp1, then on f2-sp1, and f3-sp1. In the next iteration of the loop I plot on f1=sp2, f2-sp2, f3-sp2, etc... Is anyone please able to tell me how to do this without making the figures visible? For each figure I can assign handles to the subplots with the following code,
for sp=1:4
ax(sp)=subplot(2,2,sp);
end
and then with the current figure I can move around the subplots using
subplot(ax(2))
I can do this for each figure, i.e., end up with ax1, ax2 and ax3, but using these in the codes only seems to move within the current figure. E.g.,
subplot(ax2(4))
will make subplot 4 of the current figure active, but will not necessarily make subplot 4 of figure 2 active. If I make figure 2 current using
figure(2)
then it becomes visible.
Can anyone help me with how to make a specific subplot of a specific figure current, without making the figure visible?
Thanks very much Jen
0 Comments
Accepted Answer
Thorsten
on 26 Oct 2016
Don't use
figure(2)
but
set(0, 'CurrentFigure', f(2))
where f(2) is the handle of figure 2, obtained with gcf when figure 2 is active, or returned by figure when the figure is created.
More Answers (1)
Adam
on 26 Oct 2016
hFigs(1) = figure(1);
for sp=1:4
ax(sp)=subplot(2,2,sp, 'Parent', hFigs(1));
end
hFigs(2) = figure(2);
for sp=1:4
ax(sp+4)=subplot(2,2,sp, 'Parent', hFigs(2));
end
Something like that would work better. I wouldn't store my axes indexed quite like that probably because a hard-coded +4 is ugly and it depends where your code is fitting with respect to each other as to exactly how I would do it, but the main point is to explicitly give your subplot axes a parent figure.
Relying on making something the current figure and then using the default subplot instruction is never a good idea.
2 Comments
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!