how can i align two arrays according to their clock

8 ビュー (過去 30 日間)
song
song 2014 年 10 月 22 日
コメント済み: song 2014 年 10 月 23 日
i have 2 sets of data A and B . both A and B is a 4096*2 vector. the first col is data ,second col is Corresponding sample clock.
if true
% code
[data(:,1),time(:,1)]=textread('1.txt','%n%n');
[data(:,2),time(:,2)]=textread('2.txt','%n%n');
end
i plot the data and it looks like Fig 1
if true
% code
plot(data);
end
Fig1
I also plot the clock in Fig2
i want to align the data1 and data 2 according to their clok , how can i do.

採用された回答

Matt Tearle
Matt Tearle 2014 年 10 月 22 日
編集済み: Matt Tearle 2014 年 10 月 22 日
If by "align the data" you mean you want both data1 values and data2 values at some common time values, then you will probably need to interpolate both vectors onto a time vector of your choosing. This could be a little tricky given that the first 1000 values of time(:,1) and time(:,2) are pretty much constant but not equal, but anyway, in general you want to do something like this:
N = 2000;
t = linspace(min(time(:)),max(time(:)),N); % make a vector of times
data1 = interp1(time(:,1),data(:,1),t); % interpolate first column of data onto t
data2 = interp1(time(:,2),data(:,2),t); % interpolate second column of data onto t
plot(t,data1)
hold on
plot(t,data2)
Now you have both data1 and data2 with N points, at the time values given in t. You can be fancier about how you make t, such as using intersect or union.
[If by "align" you just mean see them aligned on the plot, then just do what Orion suggested.]
  1 件のコメント
song
song 2014 年 10 月 23 日
thank you i will try your method .

サインインしてコメントする。

その他の回答 (1 件)

Orion
Orion 2014 年 10 月 22 日
just do :
plot(time,data)
  1 件のコメント
song
song 2014 年 10 月 23 日
thank you ,but you misunderstood my mind.

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by