2017-03-01 34 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)。