フィルターのクリア

delete dates from a matrix

2 ビュー (過去 30 日間)
elisa ewin
elisa ewin 2017 年 4 月 3 日
コメント済み: Jan 2017 年 4 月 3 日
I have a matrix of dates [year, month, day, hour, minutes, seconds] ex:
A=[2004 6 18 13 8 0; 2004 7 19 13 45 2; 2004 8 18 13 8 13;2004 8 18 13 9 41;2004 9 18 13 9 50;2005 1 20 13 12 38; 2005 1 17 13 12 45; 2005 2 12 12 12 23; 2005 4 12 12 12 24; 2005 4 12 12 13 49; 2005 12 12 12 13 49; 2005 12 12 12 28 20]
and I want to delete all the dates before (2004 7 22 13 23 11) and after (2005 11 23 12 14 1), can you help me?
I want how result
A=[2004 8 18 13 8 13;2004 8 18 13 9 41;2004 9 18 13 9 50;2005 1 20 13 12 38; 2005 1 17 13 12 45; 2005 2 12 12 12 23; 2005 4 12 12 12 24; 2005 4 12 12 13 49]
thanks

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 4 月 3 日
編集済み: Andrei Bobrov 2017 年 4 月 3 日
A=[2004 6 18 13 8 0;
2004 7 19 13 45 2;
2004 8 18 13 8 13;
2004 8 18 13 9 41;
2004 9 18 13 9 50;
2005 1 20 13 12 38;
2005 1 17 13 12 45;
2005 2 12 12 12 23;
2005 4 12 12 12 24;
2005 4 12 12 13 49;
2005 12 12 12 13 49;
2005 12 12 12 28 20];
tr = [2004 7 22 13 23 11; 2005 11 23 12 14 1];
trn = datenum(tr);
An = datenum(A);
Aout = A(An >= trn(1) & trn(2) >= An,:);

その他の回答 (2 件)

KSSV
KSSV 2017 年 4 月 3 日
A=[2004 6 18 13 8 0; 2004 7 19 13 45 2; 2004 8 18 13 8 13;2004 8 18 13 9 41;2004 9 18 13 9 50;2005 1 20 13 12 38; 2005 1 17 13 12 45; 2005 2 12 12 12 23; 2005 4 12 12 12 24; 2005 4 12 12 13 49; 2005 12 12 12 13 49; 2005 12 12 12 28 20] ;
d0 = [2004 7 22 13 23 11];
d1 = [2005 11 23 12 14 1] ;
Ad = datetime(A) ;
d0d = datetime(d0) ;
d1d = datetime(d1) ;
iwant = Ad(Ad>d0d & Ad < d1d)
datevec(iwant)
  1 件のコメント
Jan
Jan 2017 年 4 月 3 日
+1: This uses the modern datetime methods. A simplification:
% Directly instead of datevec(Ad(...))
iwant = A(Ad>d0d & Ad < d1d, :)

サインインしてコメントする。


Jan
Jan 2017 年 4 月 3 日
編集済み: Andrei Bobrov 2017 年 4 月 3 日
A = [2004 6 18 13 8 0; ...
2004 7 19 13 45 2; ...
2004 8 18 13 8 13; ...
2004 8 18 13 9 41; ...
2004 9 18 13 9 50; ...
2005 1 20 13 12 38; ...
2005 1 17 13 12 45; ...
2005 2 12 12 12 23; ...
2005 4 12 12 12 24; ...
2005 4 12 12 13 49; ...
2005 12 12 12 13 49; ...
2005 12 12 12 28 20];
D = datenum(A);
Keep = datenum([2004 7 22 13 23 11]) <= D & D <= datenum([2005 11 23 12 14 1]);
B = A(Keep, :);

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by