Matlab - How to make a figure current? How to make an axes current?

Evgeni Sergeev picture Evgeni Sergeev · Oct 8, 2012 · Viewed 67.2k times · Source

If f is the figure handle, I wanted to use plot3(..) on it just like I would use plot(..), but this didn't work:

>> plot3(f, t, real(Y), imag(Y))
Error using plot3
Vectors must be the same lengths.

Then I figured out that the way to do this is to:

  1. First make the relevant figure current.

  2. Then use the plot3(..) function.

I can find what the current figure is using gcf, but how do I make a figure current (via its handle)?

Answer

Rody Oldenhuis picture Rody Oldenhuis · Oct 8, 2012

This method has my personal preference:

set(0, 'currentfigure', f);  %# for figures
set(f, 'currentaxes', axs);  %# for axes with handle axs on figure f

because these commands are their own documentation. I find

figure(f)

and the like confusing on first read -- do you create a new figure? or merely make an existing one active? -> more reading of the context is required.