2012-04-27 133 views
0
clear all 
depth1 = [0;2;3;4;5;6;8;10;12;14;16;18]; 
depth2 = [0;2;3;4;5;6;7;8;9;10;11;12]; 
depth3 = [0;4;6;8;10;12;14;16;18;20;22;24]; 
Depth = {depth1,depth2,depth3}; 

data1 = [0.8,0.797,0.796,0.795,0.795,0.795,0.797,0.798,0.8,0.802,0.803,0.802]; 
data2 = [0.764,0.752,0.743,0.745,0.746,0.736,0.710,0.656,0.584,0.574,0.577,0.601]; 
data3 = [0.760,0.750,0.745,0.714,0.593,0.354,0.257,0.272,0.295,0.327,0.368,0.379]; 
Data = {data1;data2;data3}'; 

coloring = {[0 0 0],[1 0 0],[0 0 1]}'; 
marking = {'+','o','s'}; 

for i = 1:length(Depth); 
    fh = figure(1); 
    plot(Depth{i},Data{i},'color',coloring{i},'Marker',marking{i});hold on; 
    legend; 
    set(fh,'color','white'); 
    set(gca,'TickLength',[.01 .01],'TickDir','out','box','on','XMinorTick','on',... 
     'YMinorTick','on','FontName','Helvetica','FontSize', 14,... 
     'Fontweight','demi','XColor','k','YColor','k');  
end 

此示例顯示了一個繪圖,其中每個測量的深度變化的不同深度處測量了三個不同變量。我想知道是否可以更改x軸,以便顯示的範圍從0到1不等,分別代表最小和最大深度。這可能嗎?更改繪圖中的x軸範圍

,我已經使用當前的方法是:

newDepth = cellfun(@(x)linspace(0,1,length(x)),Depth,'un',0); 

,然後繪製數據對這種新的深度向量。

for i = 1:length(Depth); 
    fh = figure(1); 
    plot(newDepth{i},Data{i},'color',coloring{i},'Marker',marking{i});hold on; 
    legend; 
    set(fh,'color','white'); 
    set(gca,'TickLength',[.01 .01],'TickDir','out','box','on','XMinorTick','on',... 
     'YMinorTick','on','FontName','Helvetica','FontSize', 14,... 
     'Fontweight','demi','XColor','k','YColor','k');  
end 

有沒有更好的方法?

回答

0

我認爲你是正確的變量錯誤的方式。使用cellfun(@(x)linspace(0,1,length(x)),Depth,'un',0);的x軸值的當前歸一化簡化了每個向量的元素之間的關係。我認爲,正確的方法將是,

newDepth = cellfun(@(x)(((x)-(min(x)))'./((max(x))-(min(x)))'),Depth,'un',0); 

這樣,除未歸一化depths的不同元件的相對間距在歸一化值被保留爲好。使用這個,讓我知道。我確定使用newDepth = cellfun(@(x)linspace(0,1,length(x)),Depth,'un',0);獲得的歸一化圖不正確。你只是沒有意識到這一點,因爲次要的錯誤縮放並沒有在規範化的圖表中表現得非常明顯。

至於繪製循環圖的方法,我現在覺得很好。你究竟發現了什麼錯誤?

+0

很好用。現在一切都好了。謝謝你的幫助。 – Emma 2012-04-27 16:40:24