2013-05-13 62 views
0

如何使兩個圖的垂直軸相等?爲兩個數字設置y軸的等值極限

例如:

a = [1 2 3; 21 1 3; 4 2 3; 4 5 6] 

繪製plot(a(1, :))我得到如下圖後:
enter image description here

我已經做了一些簡單的操作:

[U E V] = svd(a); 
figure(2); 
plot(U(1,:)) 

並得到另一個數字: enter image description here

如何使兩個圖的y軸極限相等?它是否與axes equal命令?

UPDATE:
我用下面的命令:

figure (1) 
ylim([0 3]) 
plot(a(1,:)) 
figure (2); 
ylim([0 3]) 
plot(U(1,:)) 

但得到相同的結果...

回答

1

您可以使用ylim強制在y軸的限制。例如:

figure(1) 
%// Some plotting... 
ylim([0 3]) 

figure(2) 
%// Some more plotting 
ylim([0 3]) 

這確保了y軸被限制在範圍[0,3]中兩條曲線。您可以使用命令xlim對x軸的極限值進行相同操作。

另請注意,如果要一次設置兩個軸的限制,而不是使用xlimylim(兩個命令),則可以使用axis(一個命令)。

+0

這是否使軸和y軸平等的嗎? – 2013-05-13 16:13:09

+0

彼此不同的圖形,例如在我的情況下,y軸的尺度彼此不同,我可以讓它們彼此相等嗎? – 2013-05-13 16:14:05

+0

@dato MATLAB自動設置y軸的極限。 'ylim'手動強制限制你所決定的值。如果你想確保限制是相同的使用'ylim'具有相同的值的兩個圖。 – 2013-05-13 16:15:39

1

您可以使用ylimxlim函數。

1

您可以克隆一個情節的限制另一地塊以這種方式:

h1 = figure; 
% do first plot... 

h2 = figure; 
%do second plot... 

% set first figure as active 
figure(h1); 

%get limits properties of the axes that are drawn in Figure 1 
xL = get(gca, 'XLim'); 
yL = get(gca, 'YLim'); 

%switch to second figure and set it as active 
figure(h2); 

%set axis limit properties of Figure 2 to be the same as in Figure 1 
set(gca, 'XLim', xL); 
set(gca, 'YLim', yL);