2013-07-29 53 views
1

次要情节的例子这里给出:标签次要情节在Matlab

http://www.mathworks.com/support/solutions/en/data/1-16BSF/?product=SL&solution=1-16BSF

figure(1) 
surf(peaks(10)) 
colorbar 

figure(2) 
mesh(peaks(10)) 
colorbar 

figure(3) 
contour(peaks(10)) 
colorbar 

figure(4) 
pcolor(peaks(10)) 
colorbar 

% Now create destination graph 

figure(5) 
ax = zeros(4,1); 
for i = 1:4 
ax(i)=subplot(4,1,i); 
end 

% Now copy contents of each figure over to destination figure 
% Modify position of each axes as it is transferred 

for i = 1:4 
figure(i) 
h = get(gcf,'Children'); 
newh = copyobj(h,5) 
for j = 1:length(newh) 
posnewh = get(newh(j),'Position'); 
possub = get(ax(i),'Position'); 
set(newh(j),'Position',... 
[posnewh(1) possub(2) posnewh(3) possub(4)]) 
end 
delete(ax(i)); 
end 
figure(5) 

如何将一个在这个例子中的标签添加到次要情节?只是增加'图1''图2'等将是有益的。

+0

你想添加什么样的标签? –

+0

在我的应用程序中,我创建了一组文件内容的直方图,并且希望用文件名来标记每个直方图,即''CFZ12'' – siegel

回答

1

添加两行脚本像这样的结尾:

string = {'Figure 1','Figure 2','Figure 3','Figure 4'}; %%% or any titles you want 
for i = 1:4 
figure(i) 
title(string{i}) %%% add this line 
h = get(gcf,'Children'); 
newh = copyobj(h,5) 
for j = 1:length(newh) 
posnewh = get(newh(j),'Position'); 
possub = get(ax(i),'Position'); 
set(newh(j),'Position',... 
[posnewh(1) possub(2) posnewh(3) possub(4)]) 
end 
delete(ax(i)); 
end 
figure(5) 
1

你能不能在脚本的末尾使用

figure(5) 
subplot(4,1,1) 
title('first figure') 
subplot(4,1,2) 
... 

?或者我错过了什么?

或者在原始图中使用title例如,

figure(1) 
surf(peaks(10)) 
title('first figure') 
+0

您的第一个建议清除了数字(至少在某些版本的Matlab )。第二个不起作用,因为标题不被复制 –

4

我想很多人都会为了找到一种方法,只是一个标题添加到一个插曲没有碰到过这样的条目任何复制(像我一样)。对于这种情况,它可以很容易地通过桑杰·马诺哈尔已经说明做:

figure(1) 

subplot(4,1,1) 
surf(peaks(10)) 
title('Figure 1') % must come AFTER the plot command 
colorbar 

subplot(4,1,2) 
mesh(peaks(10)) 
title('Figure 2') % must come AFTER the plot command 
colorbar 

subplot(4,1,3) 
contour(peaks(10)) 
title('Figure 3') % must come AFTER the plot command 
colorbar 

subplot(4,1,4) 
pcolor(peaks(10)) 
title('Figure 4') % must come AFTER the plot command 
colorbar 

这里最重要的部分是(我想这是最错误的来自)的title -command必须跟从实际的绘图命令。如果它是在绘制图表之前编写的,则标题不会出现!