フィルターのクリア

Remove rows by time with datenum

2 ビュー (過去 30 日間)
David du Preez
David du Preez 2017 年 7 月 14 日
編集済み: dbmn 2017 年 7 月 14 日
Hi.I have a mx15 matrix. In column 1 are datenum values (datenum(Y,M,D,H,MN,S)). I want to remove rows if the time is earlier than 11:00 or later than 14:00. How would one do that ?

採用された回答

dbmn
dbmn 2017 年 7 月 14 日
編集済み: dbmn 2017 年 7 月 14 日
assuming that A is your matrix with A(:,1) the column of your datenums, then simply do
% Determine which rows to delete
% (note that the "hours" of datenum are behind the decimal point)
% hence we do mod 1 to just get that number
rows_to_delete = mod(A(:,1),1)<11/24 | mod(A(:,1),1)>14/24;
% Delete them
A(rows_to_delete, :) = [];
Or if you are using a newer version of matlab you could get to some extra comfort and use datetime
% Convert to datetime
new_time = datetime(A(:,1), 'ConvertFrom', 'datenum');
% Determine which rows to delete
rows_to_delete = hour(new_time)<11 | hour(new_time)>14;
% Delete them
A(rows_to_delete, :) = [];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFractals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by