How to Compare two arrays with timestamps/datetime using one timestamp/datetime as reference and merge them into one
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a 2-column cell array of elevation data like so:

The date time in this array is in the format: m/d/yyyy hh: mm . The length/number of rows of elevation data is 9537. Assume seconds (secs) values of the date time are zero.
I have another 2-column cell array of rain data like so:


The date time in this array is in the format: dd-mmm-yyyy hh:mm:ss .The length/number of rows of the rain data is 527040.
I want to have an array of data like the table below Using the elevation data timestamp as reference, I would like to insert the rain data equivalent into the third column like so. I have done the first 10 values manually:

Coincidentally, from the above table, the raindata is 0 for the first 10 elevation angles but varies further down the line. The code should ignore the seconds (secs) values in the rain data since they are zero anyways. While the rain datetime is steadily increasing in steps of 1minute (60secs), the elevation data on the other hand, although still in steps of 1minute has some data missing in between, hence inconsistent data. However, for every elevation data value there is a corresponding rain data value.
I have written this code but it is not working. I am not so familiar with for loops and IF statements. Is there a way to do this without using for loops or IF statements. Could you point me in the direction as to where I can find answers to this problem or kindly, solve this?
For 1=1:length(elevation);
if elevation==find(t==elevation(i,1));
raindata = t(elevation,2);
elevation(i,3) = rain data;
end
continue
end
4 Kommentare
Antworten (1)
Steven Lord
am 22 Jan. 2018
Bearbeitet: Steven Lord
am 22 Jan. 2018
I assume from the tags that you're using release R2015a. If upgrading is a possibility, or you're using release R2016b or later and the tag was in error, I would upgrade to release R2016b or later and store the data in timetable arrays. You could then synchronize the timetable arrays.
1 Kommentar
Peter Perkins
am 22 Jan. 2018
As Steve says, this just screams out for the synchronize function.
But prior to R2016b, you can do the same "by hand" using tables, datetimes, and the join method on tables. ismember, as suggested by KSSV, would also work, but you want to apply it only to the datetime vector, to create a logical index.
The format of the datetime would make no difference.
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!