Referencing common set from two similar matrices

1 回表示 (過去 30 日間)
Jonathan
Jonathan 2011 年 10 月 7 日
Hi,
I have a two large sets of time series from two instruments to compare to each other. The time series come from about 70 distinct days, and both instruments recorded on each of these days.
Time series (t0 to tn) from instrument X and from instrument Y are both reported at 1 HZ, both as seconds since midnight, both continuous and monotonically increasing, (e.g. 11201, 11202, 11203...), are always in column 1, but are not always identical in length (i.e. number of time steps). Sometimes, X starts before Y, sometimes Y before X. Sometimes X ends before Y, sometimes Y before X. There is always overlap, however.
I'm interested in finding the common set of these time series as simply as possible, and then would like to reduce each to that common length. The two time series have different numbers of columns, though (one reports just 3 variables, while another reports 10), so the two final files will only be dimensionally identical in number of rows.
My grasp of logical indexing, find functions and higher level Matlab functions is still pretty new, so I've been going about this with a series of FOR and IF statements that involve lots of variables comparing values of timestep(t0) and t(n). However, my code is getting far too long and is generating too many variables. I'm sure the same can be done MUCH more easily if I knew how. And, since there are a lot of these files, excessive IF/FOR statements like I'm doing really bog down the code.
Can anyone suggest how to go about this efficiently? I'm capable of writing the eval functions that run the same processes on multiple different, but similarly-formatted file names, but just getting those sets the same length has me stuck...
Many TIA, Jonathan
  2 件のコメント
Dr. Seis
Dr. Seis 2011 年 10 月 7 日
1. The timeseries is evenly spaced and does not have data gaps, right?
2. One just stops a littler sooner, or starts a little later?
3. Are you saying the time associated with each sample is stored in column 1 and the measured value in column 2?
Jonathan
Jonathan 2011 年 10 月 8 日
Thanks, Elige. Yes, those are corrected. Fangjun's suggestion solved my problem elegantly, so I'm all set. Thanks to you both for the help.

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 10 月 7 日
It sounds like you just need intersect()
X=[(1:10)',rand(10,3)];
Y=[(5:15)',ones(11,5)];
[C,Ix,Iy]=intersect(X(:,1),Y(:,1));
ComX=X(Ix,:)
ComY=Y(Iy,:)
  1 件のコメント
Jonathan
Jonathan 2011 年 10 月 8 日
Thanks very much--this helped and solved my issue perfectly.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTime Series についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by