Selecting specific time from date and time array?
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a csv file which has been attached. I have imported the two columns in Matlab cell array using the following codes
fid =fopen('Actual_38.05_-75.45_2006_UPV_61MW_5_Min.csv');
textData = textscan(fid,'%D%f','headerlines',1,'delimiter',',');
fclose(fid)
a = textData{1,1};
b = textData{1,1};
The first column is time from 1/1/2006 to 12/31/2006 sampling each 5 minutes, e.g. (1/1/2006 0:20 and 1/1/2006 0:25). What I want is to select times from 8am to 8pm and its corresponding second column values for all 365 days of year. How can I do it through a loop? I think my first problem is that I cannot find 1/1/2006 8:00 for start. The second problem is I do not know how extract data from 8am to 8pm for day one, i.e. 1/1/2006. The third problem is I do not know how to go to the next day and repeat this process.
댓글 수: 0
답변 (2개)
Steven Lord
2018년 7월 9일
Make a datetime vector with times spaced 15 minutes apart.
N = datetime('now');
hours48 = (N-days(1)):minutes(15):(N+days(1));
I'm going to tweak the format used to display the dates and times a bit. This doesn't change the data, just how it is displayed.
hours48.Format = 'dd MMM @ hh:mm:ss a';
Get the hour of the day for each element of the vector.
hoursOfDay = hour(hours48);
Let's find all the elements in hours48 after noon and before 3 PM.
hours48(hoursOfDay >= 12 & hoursOfDay <= 14).'
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!