Find specific date/time from a series of datenums

조회 수: 26 (최근 30일)
Louise Wilson
Louise Wilson 2019년 9월 16일
편집: Louise Wilson 2019년 9월 17일
I have a 7184x72001 double matrix where the first column is a list of serial datenumbers.
I am happy to keep the format this way, but I need to be able to select a specific date/time from this list so that I can extract the data from certain days/times that I am interested in.
So, is it either possible to:
-search from a list of datenums to find a specific date/time that I provide?
-add a column of str data to a matrix of double?
or-convert all of the datenums to date and time?
I have tried the second approach so far:
D=csvread('Tiritiri5280_PSD_1sHammingWindow_50%Overlap_output.csv'); %load in data
t=D(:,1); %extract time column
formatOut='yymmddHHMMSS';
times=datestr(t, formatOut); %convert t column datenums to date and time
rows=(1:length(times)).'; %number of dates and times we have
D_new=[rows D]; %add new column to D
D_new(:,1)=timeslist(:,2); %add times in different format to D
-this works but I now get the datenum in a different format which is also not readable. How do I keep the date time in yymmddhhmmss in a double matrix? Is this possible?
Here,column 1 is the new dates/times that I tried to insert in readable form, and column 2 is serial datenum.
  댓글 수: 2
Nicolas B.
Nicolas B. 2019년 9월 17일
Hi,
in a matrix, you have the problem that you can only have 1 data type for all your data. Maybe a cell array could help you?
Louise Wilson
Louise Wilson 2019년 9월 17일
Thank you Nicolas, I realised this shortly after asking the question. Woops-from Steven's answer, I think I will try to go with a timetable and see if that is more useful.

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2019년 9월 17일
If you're going to be doing a lot of processing of this data based on the times, consider turning your column of date numbers into a datetime array and using that datetime array to convert your data matrix into a timetable. Once you do this you could extract data from the timetable based on the times for each row using a timerange as shown in the "Subscript on Time Range" section on this documentation page. You could also resample or aggregate your timetable data using a certain time basis, as shown here.
  댓글 수: 1
Louise Wilson
Louise Wilson 2019년 9월 17일
편집: Louise Wilson 2019년 9월 17일
Thank you Steven. I would follow these steps to do this?:
t = datetime(X,'ConvertFrom','datenum')
TT = array2timetable(X,'RowTimes',rowTimes)
Would this work, given the values populated in my cells? They are decibel values with five decimal places.
I'm not sure why I am using datenum to be honest... I started my Matlab endeavors using code from a past grad student at the lab where I am working (to answer the same questions but with different data) and all of her code uses those, for some reason I am yet to figure out. My raw date/time data comes in the format yyddmmHHMMSS. Can you convert this format directly to datetime? Also, using a timetable, am I able to use the rowtimes? I'd like to plot them as the x-axis values in a plot.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ted Shultz
Ted Shultz 2019년 9월 17일
It looks like the start of your approach is reasonable. Once you make a “times” array, there is no need to add it back to the “D” matrix. You can use that as your index.
For example:
indexOfInterest = (times > t_one) && (times < t_two);
someData =d(indexOfInterest, :);

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by