如何在MATLAB中为4个子图创建一个通用图例?

如何在MATLAB中为4个子图创建一个通用图例?,matlab,legend,subplot,Matlab,Legend,Subplot,如何在MATLAB中为4个子地块创建一个通用图例,如下所示: 又快又脏: hSub = subplot(3,1,1); plot(1,1,1,1,1,1,1,1); hLegend = legend('hello','i','am','legend'); subplot(3,2,3), plot(10:-1:1); subplot(3,2,4), plot(1:100); subplot(3,2,5), stem(1:10); subplot(3,2,6), plot(randn(1,100)

如何在MATLAB中为4个子地块创建一个通用图例,如下所示:

又快又脏:

hSub = subplot(3,1,1); plot(1,1,1,1,1,1,1,1);
hLegend = legend('hello','i','am','legend');

subplot(3,2,3), plot(10:-1:1); subplot(3,2,4), plot(1:100);
subplot(3,2,5), stem(1:10); subplot(3,2,6), plot(randn(1,100))

set(hLegend, 'position', get(hSub, 'position'));

我以前尝试过这个方法,但它的缺点是,传奇人物将主要的子地块缩小了。我碰巧知道一个解决方案。您只需将图例添加到最后一个子图中,然后将图例拖动到您想要的位置。(最后一个子图将调整其大小,这样您就不用担心了):|但实际上我想找到一个MATLAB函数(例如使用“suptitle”为子图添加公共标题)或一些MATLAB代码来实现这一点。如果你现在找到了这个函数,请告诉我。非常感谢。