how can results of two separate m files be plotted in same figure window

Illustration
annabelletaylor - 2020-03-04T14:47:34+00:00
Question: how can results of two separate m files be plotted in same figure window

figure window after execution of first program should not close. when second m file is executed result of second program should be plotted in first figure window

Expert Answer

Profile picture of Neeta Dsouza Neeta Dsouza answered . 2025-11-20

The following example functions plot in the current figure window with lines held on to the same axes.

- function test1 calling test2 is completely irrelevant in this context. they can be called seperately too.

- instead of using gca you can also pass the handle of axes or figure to the other function so that it use the same to plot

- if not super imposed, you can use the subplot function to plot multiple axes on a single figure window

e.g.

 

function test1()
    plot(1:10);
    hold on;
    test2();
end
function test2()
    plot(gca,2:20);
end


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!