Info

此问题已关闭。 请重新打开它进行编辑或回答。

Eliminate points in 2 different conditions

1 次查看(过去 30 天)
Tiago Dias
Tiago Dias 2018-3-13
关闭: MATLAB Answer Bot 2021-8-20
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.

回答(2 个)

Image Analyst
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 个评论
Tiago Dias
Tiago Dias 2018-3-13
编辑:Tiago Dias 2018-3-13
yeah, my datetime has to be numbers, thats what i change and the symbol "&" works fine. sorry for the time waste.
Had to do, so the result is not time, but its 1, row 1
t1 = find(data(:,1)==t1);

Steven Lord
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 个评论
Tiago Dias
Tiago Dias 2018-3-13
my time+data is a timatable, my data with variables is in a double, each row is a time, so 01/01/2016 00:00:00 is the first row, 01/01/2016 00:01:00 the second row and so on.
thats why with a find, i can know which row the datetime represents, and it is easier, and this way i can use & because it is all numbers. So that solves my problem. becuase i just wanted to do in 1 for loop instead of 3.

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by