Search code examples
matlabnestedfigure

Activate a specific figure when returning from a nested function


I have a plotting function inside imshow() command.

The plot and the image should be in separate figures.

At the return from the inside function the current figure is of the plot thus imshow() puts the image onto the same figure of the plot and kills the plot.

What can be done to make imshow() open or get to an existing its own figure, while keeping such manner of nested function calling?


Solution

  • Apparently, I've found an answer:

    1. open a figure before imshow(nested_function());
    2. upon starting the nested_function() save the handle to the previous figure like fh_prev = gcf; for example
    3. do any plots along the nested_function()
    4. before return from the nested_function() activate the previous figure with the command figure(fh_prev);