2013-07-29 78 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必須跟從實際的繪圖命令。如果它是在繪製圖表之前編寫的,則標題不會出現!