Info
此问题已关闭。 请重新打开它进行编辑或回答。
Eliminate points in 2 different conditions
1 次查看(过去 30 天)
显示 更早的评论
Hello, I have data from 01/01/2016 00:00:00 until 03/11/2017 00:00:00, and with values associated with variable X1, X2, etc
Data X1 X2 X3
01/01/2016 5 6 7
...
03/11/2017 8 9 10
I want to turn some values into NaN for 2 different intervals of time
t1 = '01/01/2016 00:00:00'
t2 = '01/04/2016 00:00:00'
t3 = '01/08/2016 00:00:00'
t4 = '01/11/2016 00:00:00'
Instead of doing with 2 for's, I wanted to know if it is possible to do this with just one for with an "and" or a "&", I tried "&" but doesn't work.
for i = t1:t2
tabel(i,:) = NaN;
end
for i = t3:t4
tabel(i,:) = NaN;
end
Thanks for your time.
0 个评论
回答(2 个)
Image Analyst
2018-3-13
All rows in a table's column must be of the same type. So, since nan is not a date type, it won't let you. You might just have to delete the rows you don't want, or extract a new table with the rows that you DO want.
1 个评论
Steven Lord
2018-3-13
How are you storing your data? Are you storing it in a timetable?
t = (datetime(2016, 1, 1):datetime(2016, 2, 1))';
A = randi([-10 10], numel(t), 3);
tt = array2timetable(A, 'RowTimes', t)
If you want to select all the rows whose values lie in a particular interval of time, use timerange.
startDate = datetime(2016, 1, 10);
endDate = datetime(2016, 1, 16);
interval = timerange(startDate, endDate)
tt(interval, :)
You can use that to index into the Time of the timetable and replace times that fall inside that interval with NaT (Not-a-Time):
tt.Time(interval) = NaT
Or you can use an interval to work with timetable variables.
interval2 = timerange(endDate, endDate+7);
tt{interval2, 'A1'} = 2*tt{interval2, 'A1'}
1 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!