Selecting specific time from date and time array?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Steven Lord
il 9 Lug 2018
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 Commenti
Vedere anche
Categorie
Scopri di più su Dates and Time in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!