2017-03-01 66 views
0

我試圖繪製2個時間序列矢量,其是不一樣的長度:繪製矢量是不一樣的長度

  • E_Real(1x1的)與1481409個元素雙時間序列「採樣速率= 0001」。
  • E_Guess(1x1)帶384426個元素的雙倍時間序列「採樣率= 0,0059」。

MATLAB不抱怨繪製這兩個載體,並顯示如下圖:

enter image description here

我的問題是,藍線紅色的前結束,它看起來並不好(因爲矢量不具有相同的長度)。我試着解決在使用interp1這個問題:

x = 0:0.0059:1481409; % this will make x a Array of Point from 0 to 1481409  
y = interp1(E_Guess.Time,E_Guess.Data,x); 

這是爲了創建一個基於E_Guess一個新的向量y,並且具有相同的長度E_Real。但是,我總是得到y=0沒有任何錯誤消息。

這種方法有什麼問題?

+0

你想讓紅色和藍色的線條從左到右一直走到圖的左側? –

回答

1

我有一種感覺,你沒有正確使用數據的「x軸」。 看看下面的代碼:

function q42538517 

y = @(x)0.9/1000*x; 
x_Real = linspace(0,1481409*0.001,1481409); 
E_Real = y(x_Real); 

x_Guess = linspace(0,384426*0.0059,384426); 
E_Guess = movmean(y(x_Guess) + 0.1*sin(x_Guess/100) + 0.05*randn(1,384426), ... 
        10, 'Endpoints', 'shrink'); 

% What you're probably doing: 
figure(); 
plot(E_Guess,'b','LineWidth',3); hold on; plot(E_Real,'r','LineWidth',3); 
ylim([0,2.5]); 

% What you probably should be doing: 
figure(); 
plot(x_Guess,E_Guess,'b','LineWidth',3); hold on; plot(x_Real,E_Real,'r','LineWidth',3); 
xlim([0 1500]); ylim([0,1.5]); 

其中在分別的結果:

enter image description here

enter image description here

由於E_Real具有較短時間程度E_Guess1481409*0.001 < 384426*0.0059) - 沒有必要插入較長的一個,以適應短,j如上所示,ust剪下x軸(通過xlim)。