2012-03-15 22 views
2

enter image description here有沒有一種方法可以解決在Matlab中繪圖的最終效果?

WaterFraction=[0.705 0.047 -0.15 -0.046 0.18 -0.070 -0.089 -0.0815 -0.0731 -0.08 ... 
        -0.43 -0.537 -0.543 -0.62 -0.548 -0.55 -0.33 -0.112 0.10 0.0590 ] 
Radius=[ -1.25 -0.811 -0.448 -0.320 -0.384 -0.0923 0.168 0.1039 0.039 0.276 ... 
     -0.127 -0.137 -0.1088 -0.080 0.0220 0.049 2.34 4.58 6.84 -8.0] 

當我繪製通過其時間矢量數據矢量,並且兩者都是當然具有相同的尺寸,有時出現這種情況,這是令人不愉快的視覺。

我指的是從結尾返回原點的直線。 Best, Abid

+0

你可以發佈你正在繪製的數據的樣本嗎?第一個和最後10個'[t,x]'值應該這樣做。 – 2012-03-15 04:02:39

+0

x(end)的值是多少? – tmpearce 2012-03-15 04:03:30

+0

你正在使用什麼'plot'命令? – tmpearce 2012-03-15 04:23:30

回答

3

根據您的具體情況,您有幾個選項。您可以對數據進行排序以防止出現不連續性,也可以將幾個NaN插入到X和Y向量中。

  1. 排序:

    [xSorted, ixsSort] = sort(x); 
    ySorted = y(ixSort); 
    plot(xSorted, ySorted); 
    
  2. 要添加的NaN,你需要做一些額外的工作,以確定在何處休息是應該的,然後插入NaN的。例如,要在第10個條目後打破線條

    編輯:請參閱下面的示例代碼以獲得更全面的示例。

  3. 當然,作爲一種簡單的備份,只是做一個散點圖,而不是線圖:

    %Some sample data 
    x = [1:10 2.1:11 3.2:12]; 
    y = randn(size(x)); 
    
    %Define where breaks are needed (and associated boundaries) 
    ixsBreaksNeeded = find(diff(x)<0); 
    ixsSegmentBoundaries = [0 ixsBreaksNeeded length(x)]; %This makes the iterations a lot easier 
    
    %Predefine some nan vectors to move data into 
    xBroken = nan(1, length(x) + length(ixsBreaksNeeded)); 
    yBroken = nan(1, length(x) + length(ixsBreaksNeeded)); 
    
    %Move data segments into nan vectors, leaving gaps between segments 
    ixOffset = 0; 
    for ix = 2:length(ixsSegmentBoundaries) 
        ixsOriginal = (ixsSegmentBoundaries(ix-1)+1):ixsSegmentBoundaries(ix); 
        xBroken(ixsOriginal + (ixOffset)) = x(ixsOriginal); 
        yBroken(ixsOriginal + (ixOffset)) = y(ixsOriginal); 
        ixOffset = ixOffset+1; 
    end 
    
    %Plot to demonstrate 
    subplot(211) 
    plot(x,y); 
    subplot(212) 
    plot(xBroken, yBroken) 
    

    plot(x, y, '.'); 
    

下面方法2某些示例代碼

+0

這些建議非常好,其中第一個和第三個我已經嘗試過,並且不適合我的數據,因爲它是一個時間序列,也是因爲它被抽樣以至於不清楚何時疏散。我也不明白你的第二個建議是什麼意思。 – Abid 2012-03-15 07:41:16

+0

對於方法2,要找到時間向後跳躍的時間序列中的點,可以使用find(diff(t)<0)並在這些位置上插入NaN – Max 2012-03-15 10:32:52

相關問題