retrieve data specific date
8 ビュー (過去 30 日間)
古いコメントを表示
hello, i'm very new in matlab.
I have 2000-2003 hourly nc files.
I have 3 questions.
1. I want to retrieve data per 10 days each month
d1= 1,2,..,10
d2=11,12,..,20
d3=21,22,..31
2. like the first question but I want data in 1 year, I mean
data=[d1 jan, d1 feb,..,d1 dec]
3. I want to retrieve data only 1 time. For example, March 4, 2002 at 15.00
here I include a bit of my nc file.
thanks for the help
0 件のコメント
採用された回答
KSSV
2022 年 6 月 7 日
You read the dates and convert them into the class datetime. For this you need to read about datetime, datenum and datestr. Once you have dates and data in hand, you can play with the indices and get the data you want.
I will make the datetime data and answer your questions.
Answer 1:
thedates = [datetime(2022,1,1):datetime(2022,12,31)]' ; % this is the datetime data, you need to get from nc files
class(thedates)
% pick each 10 days data for Jan
idx = thedates.Month==1 ;
t = thedates(idx) ; % dates for Jan month alone
idx1 = t.Day<=10 ;
t(idx1)
idx2 = t.Day > 10 & t.Day <=20 ;
t(idx2)
Answer 2:
idx3 = thedates.Day == 1 ;
thedates(idx3)
Answer 3:
idx4 = thedates.Month == 3 & thedates.Day == 4 ;
thedates(idx4)
Like above, you can get the indices. The same indices should be used to extract the data.
2 件のコメント
Peter Perkins
2022 年 6 月 13 日
Den, KSSV is correct in recommending datetime, but DON'T read about datenum and datestr. They are no longer recommended.
その他の回答 (1 件)
Peter Perkins
2022 年 6 月 13 日
In addition to what KSSV shows, since you say "retrieve data", I recommend that you use a timetable, and things like timerange,or subscripting with datetimes to selec t subsets of your data.
It's possible that some of your uses would benefit from having a categorical variable, not a datetime. For example
>> t = datetime(2022,1,1:365);
>> dayBin = discretize(day(t),[1 11 21 31],"categorical");
>> categories(dayBin)
ans =
3×1 cell array
{'[1, 11)' }
{'[11, 21)'}
{'[21, 31]'}
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!