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

34 次查看(过去 30 天)
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!

采纳的回答

Bruno Luong
Bruno Luong 2022-9-19
ax = subplot(1,2,2,'Parent',fig1)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by