如何为子图提供组合标题?

How to give a combined title for subplots?

我想为我的子图提供一个组合标题,而不是单独为每个图命名。 例如;

for pl=1:4
      subplot(2,2,pl)
      title('Test') 
end

给我这个:

如果我使用这个:

figure
title('Test') 
for pl=1:4
      subplot(2,2,pl)

end

我没有得到任何头衔。

我希望我的输出如下所示:

这是我的解决方案版本,在 Matlab 的命令 Window 中打印:

clear all
close all
clc
name={'first', 'second', 'third', 'fourth'};
for k = 1:4
    subplot(2,2,k);
    title(name(k));
end

希望对您有所帮助。此致。

有个小技巧。您可以执行以下操作来生成具有多个子图的图形。

h = figure 
for pl=1:4
    subplot(2,2,pl)
end

在此之后,您必须将 NextPlot 属性 设置为 'add'。这样做:

h.NextPlot = 'add';
a = axes; 

%// Set the title and get the handle to it
ht = title('Test');

%// Turn the visibility of the axes off
a.Visible = 'off';

%// Turn the visibility of the title on
ht.Visible = 'on';

希望对您有所帮助!

如果您在 MathWorks File Exchange 上有 Bioinformatics toolbox you can use suptitle. Otherwise, there's the excellent suplabel 可以执行此操作和更多操作。