Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Refresh multiple figures

Subject: Refresh multiple figures

From: HJ

Date: 17 Mar, 2014 17:33:09

Message: 1 of 7

I have a large number of figures onscreen, and their handles in a vector h_fig. Is it possible to refresh all the figures using a single call to REFRESH?

I tried the combinations I could think of [e.g. refresh(h_fig), refresh(mat2cell(h_fig)), etc.], but I can't figure out a way to get refresh to act on the entire vector of handles -- only a single figure handle at a time.

The only obvious thing I could think of would something like

for idx = 1:length(h_fig)
  refresh(h_fig(idx));
end;

but is there a way to do this without using the loop?

Thanks,

-H

Subject: Refresh multiple figures

From: matt dash

Date: 17 Mar, 2014 18:07:05

Message: 2 of 7

"HJ" <hjfarkmail.notthispart@notthisparteither.lycos.com> wrote in message <lg7bkl$9aq$1@newscl01ah.mathworks.com>...
> I have a large number of figures onscreen, and their handles in a vector h_fig. Is it possible to refresh all the figures using a single call to REFRESH?
>
> I tried the combinations I could think of [e.g. refresh(h_fig), refresh(mat2cell(h_fig)), etc.], but I can't figure out a way to get refresh to act on the entire vector of handles -- only a single figure handle at a time.
>
> The only obvious thing I could think of would something like
>
> for idx = 1:length(h_fig)
> refresh(h_fig(idx));
> end;
>
> but is there a way to do this without using the loop?
>
> Thanks,
>
> -H

I'm not sure, but is this the same as the command "drawnow expose" ?

Subject: Refresh multiple figures

From: HJ

Date: 18 Mar, 2014 03:09:08

Message: 3 of 7

"matt dash" wrote in message <lg7dk9$elp$1@newscl01ah.mathworks.com>...
> I'm not sure, but is this the same as the command "drawnow expose" ?

Hi Matt,

Thanks for the suggestion. Unfortunately neither drawnow('expose') nor drawnow do the trick -- I still have to run the FOR loop to get all the figures to refresh correctly after doing a "set(ax_handles,'pos',[a b c d])" to reposition a bunch of objects scattered across all the different open figures.

So far the FOR loop seems to be the only thing that works, but it's slow.

-H

Subject: Refresh multiple figures

From: Steven Lord

Date: 18 Mar, 2014 14:03:34

Message: 4 of 7


"HJ" <hjfarkmail.notthispart@notthisparteither.lycos.com> wrote in message
news:lg8dck$3f9$1@newscl01ah.mathworks.com...
> "matt dash" wrote in message <lg7dk9$elp$1@newscl01ah.mathworks.com>...
>> I'm not sure, but is this the same as the command "drawnow expose" ?
>
> Hi Matt,
>
> Thanks for the suggestion. Unfortunately neither drawnow('expose') nor
> drawnow do the trick -- I still have to run the FOR loop to get all the
> figures to refresh correctly after doing a "set(ax_handles,'pos',[a b c
> d])" to reposition a bunch of objects scattered across all the different
> open figures.
>
> So far the FOR loop seems to be the only thing that works, but it's slow.

I suspect that what you're describing, redrawing many figures on screen at
once, is going to be slow regardless of how you do it.

How many figures are we talking about, by the way? If you've got (for
example) 50 figures all open at once on your screen, consider whether you
actually NEED all of them open at once. Unless you have an extremely large
monitor, they're going to be quite small (tiled) or they're going to overlap
each other quite a bit (non-tiled.)

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Refresh multiple figures

From: matt dash

Date: 18 Mar, 2014 20:29:08

Message: 5 of 7

"HJ" <hjfarkmail.notthispart@notthisparteither.lycos.com> wrote in message <lg8dck$3f9$1@newscl01ah.mathworks.com>...
> "matt dash" wrote in message <lg7dk9$elp$1@newscl01ah.mathworks.com>...
> > I'm not sure, but is this the same as the command "drawnow expose" ?
>
> Hi Matt,
>
> Thanks for the suggestion. Unfortunately neither drawnow('expose') nor drawnow do the trick -- I still have to run the FOR loop to get all the figures to refresh correctly after doing a "set(ax_handles,'pos',[a b c d])" to reposition a bunch of objects scattered across all the different open figures.
>
> So far the FOR loop seems to be the only thing that works, but it's slow.
>
> -H


I'm a little confused about this. I do LOTS of work with figures but I've never had to use refresh... just drawnow.

Refresh is not a built in function, so you can view its source code. All it does is set the color of the figure and then set it back to its original color, apparently just to flag the figure as needing to be redrawn. It does not appear to actually do ANYTHING that would cause a drawnow, so I'm not sure how that works.

But the good news is this: you can just as easily use this trick with a vector of figures. Try this:

set(f,'color',[0 0 0],'color','default')

(or replace default with whatever color you want them to be. And just make sure the first color you specify is different from this)

where f is your vector of figure handles. This should do the same thing refresh does. The only reason you can't call refresh with a vector of handles is that it uses "color = get(h,'color')" and assumes it will return an array, whereas if you had a vector of figures it would return a cell array, which refresh does not check for. Kind of an oversight if you ask me...

Subject: Refresh multiple figures

From: HJ

Date: 19 Mar, 2014 16:59:09

Message: 6 of 7

"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <lg9jnc$30e$1@newscl01ah.mathworks.com>...
> I suspect that what you're describing, redrawing many figures on screen at
> once, is going to be slow regardless of how you do it.
>
> How many figures are we talking about, by the way? If you've got (for
> example) 50 figures all open at once on your screen, consider whether you
> actually NEED all of them open at once. Unless you have an extremely large
> monitor, they're going to be quite small (tiled) or they're going to overlap
> each other quite a bit (non-tiled.)

Hi Steve,

I was dealing with 40-50 figures when I posted the question originally. The reason for my question is that I needed to export them all to PNG, and found it much easier to (programmatically) save them all to disk as they were being generated, thinking I could just open them all afterward and do a bulk export.

Problem is, I'm working onsite at a client where I'm required to keep all data on their machine(s). They only have R2006b installed, and I'm finding it has quite a few annoying little glitches/bugs related to handle graphics. In this case, I can bulk-select all ~50 figures, but when they come up on screen, certain subplots' position arguments are messed up, colorbars overlap adjacent subplots, and so on. Issuing "set(h_relevant_axes,'pos',[a b c d])" works to fix all such glitches in a single go, but the subplots in question don't refresh onscreen -- hence my question about passing a vector of handles to REFRESH.

The good news is that I just tried Matt's second suggestion ('set(h_figs,'color',[0 0 0],'color',[.8 .8 .8]), and that worked beautifully.

Sorry to be asking questions about such an old version (I'm quite sure those issues were fixed long ago), and thanks very much for your help!

Regards,

-H

Subject: Refresh multiple figures

From: HJ

Date: 19 Mar, 2014 17:00:15

Message: 7 of 7

"matt dash" wrote in message <lgaaak$866$1@newscl01ah.mathworks.com>...

> But the good news is this: you can just as easily use this trick with a vector of figures. Try this:
>
> set(f,'color',[0 0 0],'color','default')
>
> (or replace default with whatever color you want them to be. And just make sure the first color you specify is different from this)
>
> where f is your vector of figure handles. This should do the same thing refresh does.

Hi Matt,

Bingo! This worked perfectly. Very clever, and thank you so much for suggesting this workaround.

Gratefully,

-H

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us