How to match two different matrices
Afficher commentaires plus anciens
Hello, I have two matrices of different lengths and this is what the scenario looks like ..
x = [...];
y = [...];
size(x) = 5800 * 16
size(y) = 450 * 14
% X & Y have dates & times in the first six columns in this form:
% year, month, day, hour, minute, second
% Each column represents a variable
% Each row represents a data sample
% A model to predict a variable in (X) after some time
...
X_time + some_time = predicted_time; % in hours
% "X_time" is the time of (X)
% "Y_time" is the time of (Y)
% Match that predicted time with the time of (Y) within a range of +/- 11 hours
for i = 1:length(x)
for j = 1:length(y)
if (predicted_time >= Y_time-11) && (Y_time+11 >= predicted_time) is True
MATCHED = [x(i,:) y(j,:) predicted_time];
end
end
end
Please, I want to know how to make this work as I tried a lot but it didn't work properly.
10 commentaires
I don't understand. You lost me at " a model to predict a variable..."
It seems that you have a set of variables in one time-series and another set variables in another time-series. What exactly do you want to do with those? What does match mean in this context?
Albert Fan
le 17 Juil 2018
If I understand your question correctly, you are asking for how to compare dates and times? If so, you can refer to this document, and you can make a datetime object by using something like:
t = datetime(Y,M,D,H,MI,S)
e.g.:
t = datetime(2003,10,24,12,45,07)
which will create a datetime object for date Oct, 10, 2013 12:45:07 (24-hour format).
If you want to add or subtract the time, you can simply do:
t.Hour = t.Hour + 2 which will add two hours to t, and it will become: Oct, 10, 2013 14:45:07 (24-hour format).
Mohamed Nedal
le 17 Juil 2018
Mohamed Nedal
le 17 Juil 2018
OK! Things are clearing up. I still don't understand what match means though. What do you want to match? This is my understanding so far:
- Each row describes the characteristics of a single storm
- All storms are available in data set 1 (SET1)
- A subset of the storms in SET1 are also available in SET2
- You want to find this subset in SET1 by matching those storms.
Is this correct so far?
If so, how do you want to match them? Do they share the same characteristics or the same time-slots. If it's the latter, then you should follow Albert Fan's advice.
A wild guess: You measure different things at the two locations, and now you want to create a dataset with 450 storms and 18 variables?
Albert Fan
le 17 Juil 2018
I see, you are trying to get something from, if I were to quote jonas's words, SET2 with the data you have in SET1, if it is recorded in SET2, is that correct? If so, then the question becomes how are you going to match the storms? Do they share anything in common? I've noticed that their location data is sort of different, right?
Mohamed Nedal
le 17 Juil 2018
Mohamed Nedal
le 17 Juil 2018
So, what you need to do is:
- Loop through each storm in SET2
- Calculate the corresponding time until it reaches the location of SET1
- Find the storm that is closest in time to this value
Right?
These are simple steps, and it seems to me that this is almost what Albert Fan proposed some comments ago. If you provide some sample data to work with, I'm sure someone will give you code now that the problem is clearly stated. I guess we also need your model though, unless you can provide the modelled time-slots.
After this discussion, the initial code actually makes some sense :)
Mohamed Nedal
le 17 Juil 2018
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

