2016-09-29 38 views
0

我有以下腳本MATLAB改變ylabel的值作爲深度

clear all; clc;close all; 

dx = 0:100:400 % in meters 
rho_30 = [ 33.2185 33.3202 33.4763 33.5851 33.6078]; 


rho_50 = [ 58.4567 58.1212 57.5382 56.8300 56.0449]; 


rho_70 = [76.1825 76.0842 75.9825 75.9252 75.9507]; 

plot(dx,rho_30, 'r', 'LineWidth', 2) % rho at depth = 30 meters 

hold on 

plot(dx,rho_50, 'b', 'LineWidth', 2) % rho at depth = 50 meters 

hold on 

plot(dx,rho_70, 'g', 'LineWidth', 2) % rho at depth = 70 meters 

grid on 

legend('rho at depth = 30m', 'rho at depth = 50m', 'rho at depth = 70m') 

xlabel('length of channel (meters)'); ylabel('depth(meters)') 

正如你可以從圖中看到,深度從80米在表面開始直到30米在底部。

我的問題:如何更改深度應該從-30開始在 表面,直到-80米,底部或ylabel應該從-30開始 至-80

+0

你的意思是'xticks'和'xticklabels'?或標籤本身? –

+0

ylabel應該是-30在表面和-80在底部,同時rho_30(紅色)應該放在頂部,rho_50(藍色)中部和rho_70(綠色)在底部。 – User1961

+0

爲什麼不把'rho_30','-rho_50'和'-rho_70'而不是'rho_30','rho_50'和'rho_70'繪圖? –

回答

1

如果你想翻轉Y軸的方向上,可以這樣做:

set(gca,'YDir','reverse'); 

gca返回句柄當前軸對象。在此set命令中,您將y軸方向('YDir')設置爲'reverse'(而不是默認值'normal')。

+0

謝謝KQS。它的工作原理,但如何改變30爲-30和80爲-80? – User1961

+0

您可以使用@Luis Mendo的建議(繪製「-rho_30」等)。這將改變一切是消極的。然後,如果需要,您可以翻轉Y軸方向。 – KQS

+0

如果你真的想更改Y軸刻度標籤而不是數據,你可以執行'set(gca,'YTick',[30 40 50 60 70 80],'YTickLabel',{' - 30',' -40',' - 50',' - 60',' - 70',' - 80'})',但它有點麻煩,很容易犯錯。 – KQS