removing rows from a timetable
Show older comments
I want to remove the first year (1985) of data (12 rows as it is monthly data) from a timetable matrix. what is the easiest way to do this?
Answers (2)
madhan ravi
on 26 Mar 2021
Edited: madhan ravi
on 26 Mar 2021
load combined_observed_vs_sim_timetable
combined_data(1 : 12, :) = [ ]
Do you want to remove the data from 1985 from your timetable or do you want to remove the first twelve rows from it? In this particular case it appears that those two operations would give the same result, but that may not always be the case.
v = (1:10).';
dt = datetime('now', 'Format', 'h:mm:ss a') + minutes(randi([30 90], 10, 1));
tt = timetable(dt, v)
Let's remove every row that takes place before 10 PM.
whatHour = hour(tt.dt);
tt(whatHour < 22, :) = []
For your application you would want to use the year function.
2 Comments
Elizabeth Lees
on 26 Mar 2021
Edited: Elizabeth Lees
on 26 Mar 2021
Steven Lord
on 26 Mar 2021
whatYear =years(combined_data)
combined_data appears to be your timetable array. You need to pass its times into years. Note when I called hours I called it not with tt as input but tt.dt, which is the datetime part of tt.
test = combined_data(WhatYear < 1986, :)=[];
Assign to test or delete rows from combined_data, not both simultaneously.
% either
% keep certain rows and make a copy
test = combined_data(WhatYear >= 1986, :);
% or delete rows and don't make a copy
combined_data(WhatYear < 1986, :)=[];
% or make a copy and then delete rows from the copy
test = combined_data;
test(WhatYear < 1986, :)=[];
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!