Referencing common set from two similar matrices

조회 수: 2 (최근 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 CenterFile Exchange에서 Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by