removing rows from a timetable
이전 댓글 표시
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?
답변 (2개)
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
Elizabeth Lees
2021년 3월 26일
편집: Elizabeth Lees
2021년 3월 26일
Steven Lord
2021년 3월 26일
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, :)=[];
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!