MATLAB Answers

Subset timetable by specific time windows/periods

3 views (last 30 days)
Louise Wilson
Louise Wilson on 25 May 2020
Edited: Louise Wilson on 25 May 2020
I have a large dataset which looks like this:
The first column is datetimes and the first row is frequency bins. The data is dB values. (1,1) is irrelevant and could be 0/NA...
I then have a table of datetimes:
where the first column is the associated datetime variable from the large dataset, second is sunrise, third is end of dawn, fourth is beginning of dusk, and fifth is sunset. The first row is irrelevant and if possible I would change it to useful variable names.
I would like to subset the large dataset using these values.
For example, if the datetime (2,1) in the dataset falls between either duskdawntime(2,2:3) or duskdawntime (2,4:5), I would like to take the corresponding row of data from the large dataset and store it in a separate dusk or dawn table. Since these time windows change every day, it is important that each row of data is distinct i.e. we compare row 2 filename with row 2 sunrise time and row 2 sunset time.
(I calculated end of dawn and beginning of dusk by adding/removing 1hr from sunrise/sunset times but I may change the size of this window)
So far, I am thinking something like this:
filenumber=height(dataset);
dawnoutput=[]; %new empty arrays for dawn and dusk
duskoutput=[];
for i=1:filenumber %where filenumber is the data row, changes on each iteration
filename=times(filenumber,1); %datetime of filename from first column in datetime matrix
sunrise=times(filenumber,2);
dawnend=times(filenumber,3);
duskstart=times(filenumber,4);
sunset=times(filenumber,5);
if (filename >= sunrise) && (filename <= dawnend)
dawnoutput(filenumber,:)=noises(filenumber,:)
elseif (filename >= dawnend) && (filename <= sunset)
duskoutput(filenumber,:)=noises(filenumber,:)
end
end
...but I am not sure if this is the most refined way.
Is this possible? Thanks in advance for any suggestions/help

  0 Comments

Sign in to comment.

Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!