Referencing common set from two similar matrices
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Dr. Seis
le 7 Oct 2011
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?
Réponse acceptée
Fangjun Jiang
le 7 Oct 2011
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,:)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Time Series dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!