need to remove some time or make time
6 次查看(过去 30 天)
显示 更早的评论
I have a datime matrice called tid with 8761 values such as tid = datetime(2015,1,1,00,00,00):hours(1):datetime(2016,1,1,00,00,00);
I'm trying to remove all the times exept the ones from 08-16 i wrote:
o=0;
for o = 9:24:8761-23
worktime(o,:) = tid([o:o+8],:)
if o>32 %remove for whole year after test
break %this to
end%this aswell
end
now it alomst devides the timetable in the manner I needed however i was expecting a row and there are some other problems becouse i don't know how to remove the Not a Times (NaT) now (pic below). I'm sure there's a better way to do this than what i'm thinking with a loop but I also have a seperat matrice with values that needs to be seperated in the same manner later so I thought test with the time first. and i don't think i can use cells in the script i have becouse of the newbcoding on my part.
I hope things are clear on what i need to do..
采纳的回答
Steven Lord
2020-5-22
Use logical indexing. The relational operators like <= and > work on datetime arrays.
tid = datetime(2015,1,1,00,00,00):hours(1):datetime(2016,1,1,00,00,00);
August16thMidnight = datetime(2015, 8, 16);
August17thMidnight = August16thMidnight + days(1);
onAugust16th = August16thMidnight <= tid & tid < August17thMidnight;
tid(onAugust16th)
5 个评论
Peter Perkins
2020-5-22
I would have thought an old-school guy like Steve would have suggested reshaping to 24x366 and deleting the first seven and last eight rows (you have to delete that last 2016 element first, though). But right, groupsummary etc. are worth looking at.
更多回答(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!