Info

This question is closed. Reopen it to edit or answer.

Eliminate points in 2 different conditions

1 view (last 30 days)
Tiago Dias
Tiago Dias on 13 Mar 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
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.

Answers (2)

Image Analyst
Image Analyst on 13 Mar 2018
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 Comment
Tiago Dias
Tiago Dias on 13 Mar 2018
Edited: Tiago Dias on 13 Mar 2018
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 on 13 Mar 2018
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 Comment
Tiago Dias
Tiago Dias on 13 Mar 2018
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!