How can I keep figures invisible when going between different figures and different subplots?

5 views (last 30 days)
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
and then with the current figure I can move around the subplots using
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.,
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
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

Accepted Answer

Thorsten on 26 Oct 2016
Don't use
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));
hFigs(2) = figure(2);
for sp=1:4
ax(sp+4)=subplot(2,2,sp, 'Parent', hFigs(2));
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.
Jennifer Davies
Jennifer Davies on 28 Mar 2017
Hi Adam I'm trying again with this code and wondered if you're able to see where I'm going wrong? I'm creating two figures, each with six subplots, using the following code:
for fig=1:2
for sp=1:6
I can then toggle between the subplots using axes, e.g., to get to subplot 4 on figure 2 I use
But this makes the figure visible. Do you know if there's a way to keep it invisible?
Thanks in advance for your help! Jen

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!