timerange in a loop
3 ビュー (過去 30 日間)
古いコメントを表示
is it possible to put dates into a loop used in timerange function?
for i=2012:2016;
s(i)=timerange('i-01-01','i-02-01')
end
0 件のコメント
採用された回答
Steven Lord
2019 年 10 月 20 日
Yes. Build datetime objects using the three-input syntax and use them to construct a timerange. I left off one of the semicolons in the example below so you can see that at each iteration a different timerange was built with a different year.
for theyear = 2012:2016
beginDate = datetime(theyear, 01, 01);
endDate = datetime(theyear, 02, 01);
TR = timerange(beginDate, endDate)
% Do something with TR
end
3 件のコメント
Steven Lord
2019 年 10 月 20 日
i did like this. but TT_mean timetablecreated just for the last year (2016),
Yes, that's correct. Each iteration through the loop you're overwriting the TT_mean variable.
i need the keep the data created for the other years also (2012-2013-2014-2015);
You could store it in a cell array, in a struct array, do whatever further processing you want to do on the January data inside the loop, or perhaps skip the timerange altogether and use groupsummary or grouptransform.
その他の回答 (2 件)
Sulaymon Eshkabilov
2019 年 10 月 19 日
Hi,
What about this:
for ii=2012:2016
H{ii-2011} = [num2str(ii), '-01-01',' : ', num2str(ii), '-02-01'];
end
Good luck.
Sulaymon Eshkabilov
2019 年 10 月 19 日
How about this way:
for ii=2012:2016
H{ii-2011,1} = [num2str(ii), '-01-01'];
H{ii-2011, 2}= [num2str(ii), '-02-01'];
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!