MATLAB: Plot in predesigned figure

#predesigned plot

Hello
I have a script, where I tell my programm to create a figure, called h ,looking like the second picture.
then in a function within the scirpt (1. picture) i want matlab to draw my desired plot into the predesigned figure h. (See function in 4. picture)
but instead, matlab doesnt draw my plot into h, matlab draws it as in the 3. picture.
How do i plot into my predesigned figure h?
Thanks for the help!

Best Answer

You can assign a handle to the axes of the figure, and reference them in your plot function.
for example:
fig1 = figure;
a = axes;
fig2 = figure;
a2 = axes;
%plot in axes in fig1:
plot(a,1:5,1:5)
%plot in axes in fig 2
plot(a2,1:5,1:5)