Comparing date/time values in Matlab/ calling out date time values to use in code
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi,
So I have to sets of data one represents wind speed, and the other represents radar rain data.
My wind data is imported from excel and consists of a column of dates and the the remaining colums are values of wind speeds for different stations at these date times.
The radar data is a hdf file that has been converetd into rain intensity in another function.
Each set of data is in time increments of 5 minutes beginning September 2020.
E.g. first 4 sets of data :
- '01-Sep-2020 00:00:00'
- '01-Sep-2020 00:05:00'
- '01-Sep-2020 00:10:00'
- '01-Sep-2020 00:15:00'
I have looking to add a line that will compare the date/time values of the wind data to the date/time values of the radar data for each time point.
When the code finds a match, it can then be used in two other functinos I have.
A suggested start is
for i = 1:length(WindDatetime)
if RadarDatetime == WindDatetime(i)
then the file of interest == i
else
i =i +1;
end
end
However, this is not working for me.
I will insert the last part of my code that turns the date time vectors into a table of numbers like so :
2020 9 1 0 0 0
2020 9 1 0 5 0
2020 9 1 0 10 0
windtime = windfive.date; % extracting the date column from excel sheet
idx = ismember(windtime,timestampDT); % show which data is missing
windtime(~idx);
Winddata = datevec(windtime); %turn wind time data into a vector
Radardata = datevec(timestampDT); % turn radar time data into a vector
Radardata(any(isnan(Radardata),2),:) =[]; % delete any 'NaN' values
Another very useful thing to me would be if anyone knows a simple way of calling out time data so that I can use it.
For example if I would like to view the data between
'08-Sep-2020 23:55:00' and '17-Sep-2020 17:45:00'
is there a way of doing this?
Thanks:)
댓글 수: 0
채택된 답변
dpb
2021년 2월 24일
Convert to a timetable and all kinds of tools are available; see <Overview Timetables> for all of the above kinds of operations
댓글 수: 4
Steven Lord
2021년 2월 25일
You don't turn a table or timetable into a timerange. You build a timerange from a pair of datetime or duration scalars. See the first example in the help text for timerange:
rng default % Make sure I get the same data every time I run this Answer
tt = array2timetable(randn(10,3),'RowTimes',datetime(2016,4,randi(15,10,1)))
tr = timerange(datetime(2016,4,3),datetime(2016,4,12),'closed')
tt4to12 = tt(tr,:)
In this code April 11th is between April 3rd and April 12th inclusive, so tt4to12 includes the first row of tt. April 1st however is not in that range, so tt4to12 does not include that row of tt.
If instead you wanted to ask "which rows of tt have Time in a specific subset" you'd want to use ismember.
rowsWith5Or11 = ismember(tt.Time, datetime(2016, 4, [5 11]))
tt5Or11 = tt(rowsWith5Or11, :)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!