方法一:继续使用subplot()
如果您希望继续使用subplot() 函数,您可以在这种情况下使用 3 和 4 的最低公倍数 (LCM)。在这种情况下,使用具有 2 行和 12 列的子图网格就足够了。这种方法的关键是让子图跨越多个位置。 subplot() 函数中的第三个参数将指示每个子图从头到尾跨越的位置。我发现 subplot 和 span 概念适用于许多语言,这就是我倾向于在 tiledlayout() 上使用它的原因。
clf;
subplot(2,12,1:4); plot(rand(5,1));
subplot(2,12,5:8); plot(rand(5,1));
subplot(2,12,9:12); plot(rand(5,1));
subplot(2,12,13:15); plot(rand(5,1));
subplot(2,12,16:18); plot(rand(5,1));
subplot(2,12,19:21); plot(rand(5,1));
subplot(2,12,22:24); plot(rand(5,1));
clf;
subplot(2,12,2:4); plot(rand(5,1));
subplot(2,12,5:7); plot(rand(5,1));
subplot(2,12,8:10); plot(rand(5,1));
subplot(2,12,13:15); plot(rand(5,1));
subplot(2,12,16:18); plot(rand(5,1));
subplot(2,12,19:21); plot(rand(5,1));
subplot(2,12,22:24); plot(rand(5,1));
方法二:使用tiledlayout()
Grid_Height = 2; Grid_Width = 12;
tiledlayout(Grid_Height,Grid_Width);
Position = 1; Height = 1; Width = 4;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
Position = 5; Height = 1; Width = 4;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
Position = 9; Height = 1; Width = 4;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
Position = 13; Height = 1; Width = 3;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
Position = 16; Height = 1; Width = 3;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
Position = 19; Height = 1; Width = 3;
nexttile(Position,[Height,Width]);
plot(rand(5,1));
Position = 22; Height = 1; Width = 3;
nexttile(Position,[Height,Width]);
plot(rand(5,1));