How to set the parent of the subplot in a neat way?

36 views (last 30 days)
I know my question could sound strange at the first glance. Here I would like explain my question in more details. My MATLAB code goes as follows.
x = linspace(0, 2*pi, 11);
fig1 = figure('Name', 'A');
fig2 = figure('Name', 'B');
ax = subplot(1,2,1);
plot(x, sin(x.^2));
I have two figures, named A and B. The parent of ax will be fig2 by default. The question is that how to set the parent of ax to be fig1 rather than fig2 explicitly when I create ax? I know I could change the parent of ax after I create using ax.Parent = fig1, i.e.,
x = linspace(0, 2*pi, 11);
fig1 = figure('Name', 'A');
fig2 = figure('Name', 'B');
ax = subplot(1,2,1);
plot(x, sin(x.^2));
ax.Parent = fig1;
Thank you!

Accepted Answer

Bruno Luong
Bruno Luong on 19 Sep 2022
ax = subplot(1,2,2,'Parent',fig1)

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!