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 件)
madhan ravi
2021 年 3 月 26 日
編集済み: madhan ravi
2021 年 3 月 26 日
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 で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!