how to find the data for same period of time ?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
pruth
am 17 Mai 2018
Beantwortet: Peter Perkins
am 17 Mai 2018
hi, I have two mat files, the first column of both files is date-time and the second column is data. I want to compare both the data sets. however, all dates and time are not same. here I want to find data from both files which has same measurement date and time. other data I won't need it. at last, i would get one mat file which would have date-time, data from first file and data from the second file. any idea how to make it possible ?
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 17 Mai 2018
Bearbeitet: Ameer Hamza
am 17 Mai 2018
Try this
data1 = load('MRRarranged.mat');
data2 = load('distro-data.mat');
dates1 = data1.MRR_arranged_data(:,1);
dates2 = data2.rawdata(:,1);
indexDates2 = ismember(dates2, dates1);
indexDates1 = ismember(dates1, dates2);
finalDates = data2.rawdata(indexDates2, 1);
finalData1 = data1.MRR_arranged_data(indexDates1, 2);
finalData2 = data2.rawdata(indexDates2, 2);
final = [table(finalDates) table(finalData1) table(finalData2)];
then you can save the variable final.
4 Kommentare
Ameer Hamza
am 17 Mai 2018
The option 'rows' only compares row-wise
A B
1 2 <- does not intersect
2 2 <- intersect
3 1 <- does not intersect
1 1 <- intersect
Since you don't want this behavior, use the command like this
[C,ia,ib] = intersect(rawdata,MRR_arranged_data)
Weitere Antworten (1)
Peter Perkins
am 17 Mai 2018
It may be that join on timetables is the way to go here.
>> load('distro-data.mat')
>> load('MRRarranged.mat')
>> tt1 = array2timetable(MRR_arranged_data(:,2:end),'RowTimes',datetime(MRR_arranged_data(:,1),'ConvertFrom','datenum'))
tt1 =
15314×3 timetable
Time Var1 Var2 Var3
____________________ ____ ____ ____
05-Apr-2018 00:00:02 0 0 0
05-Apr-2018 00:00:12 0 0 0
05-Apr-2018 00:00:22 0 0 0
05-Apr-2018 00:00:32 0 0 0
05-Apr-2018 00:00:42 0 0 0
[snip]
>> tt2 = array2timetable(rawdata(:,2:end),'RowTimes',datetime(rawdata(:,1),'ConvertFrom','datenum'))
tt2 =
2880×3 timetable
Time Var1 Var2 Var3
____________________ ____ ____ ______
05-Apr-2018 10:08:59 0 0 0.0049
05-Apr-2018 10:09:59 0 0 0.0049
05-Apr-2018 10:10:59 0 0 0.0049
05-Apr-2018 10:12:00 0 0 0.0049
05-Apr-2018 10:13:00 0 0 0.0049
[snip]
>> tt12 = innerjoin(tt1,tt2,'Key','Time')
tt12 =
69×6 timetable
Time Var1_tt1 Var2_tt1 Var3_tt1 Var1_tt2 Var2_tt2 Var3_tt2
____________________ ________ ________ ________ ________ ________ ________
05-Apr-2018 10:12:00 0 0 0 0 0 0.0049
05-Apr-2018 10:13:00 0 0 0 0 0 0.0049
05-Apr-2018 10:14:00 0 0 0 0.0006 0 0.005
05-Apr-2018 10:18:00 0 0 0 0 0 0.005
05-Apr-2018 10:19:00 0 0 0 0 0 0.005
[snip]
I can't tell if this is what you are looking fior; there are only 69 matches. It may be that you really want some form of synchronize.
0 Kommentare
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!