gcf() returns the handle to the most recent created figure, and NOT the figure that has focus. For example:
figure; plot(sin(0:0.1:2*pi), 'b-'); title('First created');
figure; plot(cos(0:0.1:2*pi), 'r-'); title('second created');
figure; plot(abs(sin(0:0.1:2*pi)), 'r-'); title('third created');
get(gcf(),'Number')
returns '3' - ok
But now selecting figure 1 with the mouse, dragging it somewhere and issuing
get(gcf(),'Number')
returns still '3'
A consequence is, that you can only plot into the most recent figure, not into any previously created ones.
You have to manually set the 'CurrentFigure' root property. e.g.
set(0,'CurrentFigure', 1);
get(gcf(),'Number')
returns now '1', and also consecutive plot commands are printed in figure #1 now.
I don't know if this is by design or a bug.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ah, stupid me.
I could have thought about calling
figure(N);
which is the way it is done in MATLAB - you are right.
I stumbled over it, because issuing a print() command did not print the active figure, but the current figure, and calling now
figure(N);
print(...);
works perfectly - thanks to the 'Position' patch.
thanks for the hint & patch - keep on going!
ben
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
gcf() returns the handle to the most recent created figure, and NOT the figure that has focus. For example:
figure; plot(sin(0:0.1:2*pi), 'b-'); title('First created');
figure; plot(cos(0:0.1:2*pi), 'r-'); title('second created');
figure; plot(abs(sin(0:0.1:2*pi)), 'r-'); title('third created');
get(gcf(),'Number')
returns '3' - ok
But now selecting figure 1 with the mouse, dragging it somewhere and issuing
get(gcf(),'Number')
returns still '3'
A consequence is, that you can only plot into the most recent figure, not into any previously created ones.
You have to manually set the 'CurrentFigure' root property. e.g.
set(0,'CurrentFigure', 1);
get(gcf(),'Number')
returns now '1', and also consecutive plot commands are printed in figure #1 now.
I don't know if this is by design or a bug.
you are right.
an easier way to select make figure N the current figure is to use the figure command:
fingure(N);
makes fingure N the current figure, creating it if it does not yet exist. This is Matlab compatible I think.
Selecting the current figure (and also the current axes) using the mouse is supported in matlab, and is on my todo list.
Shai
ah, stupid me.
I could have thought about calling
figure(N);
which is the way it is done in MATLAB - you are right.
I stumbled over it, because issuing a print() command did not print the active figure, but the current figure, and calling now
figure(N);
print(...);
works perfectly - thanks to the 'Position' patch.
thanks for the hint & patch - keep on going!
ben
> makes fingure N the current figure, creating it if it does not yet exist. This is Matlab compatible I think.
It looks like it is not created if it does not yet exist. I just filed a Feature Request on this.
BTW, what is the 'Position' patch?
Thanks,
Tormod
WRT the 'Position' patch, never mind, I found it under "Patches" (duh).