How do I write a code to filter catalogs by...

1 Ansicht (letzte 30 Tage)
Shane
Shane am 1 Jul. 2014
Kommentiert: Star Strider am 1 Jul. 2014
I want to filter two catalogs that contain the dates of certain events. I want to check to see if catalog one has any events that occurred within the same time frame as the entirety of catalog two. Seems simple enough.
Can anyone move me in the right direction on this? I'm a little new to matlab.
I know how to use matlabdate too.

Antworten (1)

Star Strider
Star Strider am 1 Jul. 2014
If they’re simply lists of dates (and perhaps times), I would convert them to date numbers (datenum) and use the intersect function.
  2 Kommentare
Shane
Shane am 1 Jul. 2014
What if a date in catalog 1 is between two values in catalog 2, but I still want to flag it? Does intersect only flag values that are exactly the same value as each other?
Star Strider
Star Strider am 1 Jul. 2014
The intersect function will only include values that are exactly the same.
I chose a deliberately difficult situation to illustrate an alternative approach, but it depends on how your data are organised between the catalogs. You might want to experiment with something like this to see if it gives you the result you want:
C1 = unique(randi(50, 1, 25)); % Test Data
C2 = unique(randi(50, 1, 25)); % Test Data
for k1 = 1:length(C1)
Ci(k1,:) = find(C2 <= C1(k1), 1, 'last');
end
It loops through the values of C1 (Catalog #1) and tests the entries in C2 to see what the greatest value in C2 is that is less than or equal to the particular entry for C1. It returns the indices of the entries in C2 (in vector Ci) that meet those criteria.
This code snippet works, but I can’t determine if it is appropriate to your data.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by