Keep only certain rows based in three column values
2 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone!
I have been trying to solve this issue, but I have no identified the workaround!
From the next data set:
YEAR MONTH DAY HOUR MINUTE SECOND WIND DIRECTION (DEGREES)
2009 1 1 0 0 0 20
2009 1 1 0 10 0 21
2009 1 1 0 20 0 24
2009 1 1 0 30 0 29
2009 1 1 0 40 0 30
2009 1 1 0 50 0 28
2009 1 1 1 0 0 24
2009 1 1 1 10 0 31
2009 1 1 1 20 0 27
2009 1 1 1 30 0 25
2009 1 1 1 40 0 29
2009 1 1 1 50 0 31
2009 1 1 2 0 0 30
2009 1 1 2 10 0 30
2009 1 1 2 20 0 25
2009 1 1 2 30 0 27
2009 1 1 2 40 0 18
2009 1 1 2 50 0 27
2009 1 1 3 0 0 27
2009 1 1 3 10 0 29
2009 1 1 3 20 0 29
2009 1 1 3 30 0 30
2009 1 1 3 40 0 30
2009 1 1 3 50 0 30
2009 1 1 4 0 0 34
2009 1 1 4 10 0 38
2009 1 1 4 20 0 43
2009 1 1 4 30 0 57
2009 1 1 4 40 0 79
2009 1 1 4 50 0 72
2009 1 1 5 0 0 65
2009 1 1 5 10 0 64
2009 1 1 5 20 0 59
2009 1 1 5 30 0 56
2009 1 1 5 40 0 51
2009 1 1 5 50 0 51
2009 1 1 6 0 0 67
2009 1 1 6 10 0 60
2009 1 1 6 20 0 61
2009 1 1 6 30 0 78
2009 1 1 6 40 0 82
2009 1 1 6 50 0 88
2009 1 1 7 0 0 87
2009 1 1 7 10 0 85
2009 1 1 7 20 0 96
2009 1 1 7 30 0 92
2009 1 1 7 40 0 99
2009 1 1 7 50 0 108
2009 1 1 8 0 0 123
2009 1 1 8 10 0 118
2009 1 1 8 20 0 101
2009 1 1 8 30 0 99
2009 1 1 8 40 0 108
2009 1 1 8 50 0 105
2009 1 1 9 0 0 104
2009 1 1 9 10 0 105
2009 1 1 9 20 0 101
2009 1 1 9 30 0 95
2009 1 1 9 40 0 96
2009 1 1 9 50 0 101
2009 1 1 10 0 0 96
2009 1 1 10 10 0 113
2009 1 1 10 20 0 126
2009 1 1 10 30 0 107
2009 1 1 10 40 0 105
2009 1 1 10 50 0 88
2009 1 1 11 0 0 86
2009 1 1 11 10 0 72
2009 1 1 11 20 0 72
2009 1 1 11 30 0 70
2009 1 1 11 40 0 79
2009 1 1 11 50 0 81
2009 1 1 12 0 0 90
2009 1 1 12 10 0 101
2009 1 1 12 20 0 106
2009 1 1 12 30 0 100
2009 1 1 12 40 0 102
2009 1 1 12 50 0 93
2009 1 1 13 0 0 96
2009 1 1 13 10 0 91
2009 1 1 13 20 0 97
2009 1 1 13 30 0 100
2009 1 1 13 40 0 94
2009 1 1 13 50 0 101
2009 1 1 14 0 0 86
2009 1 1 14 10 0 86
2009 1 1 14 20 0 88
2009 1 1 14 30 0 87
2009 1 1 14 40 0 93
2009 1 1 14 50 0 98
2009 1 1 15 0 0 92
2009 1 1 15 10 0 92
2009 1 1 15 20 0 79
2009 1 1 15 30 0 79
2009 1 1 15 40 0 85
2009 1 1 15 50 0 89
2009 1 1 16 0 0 95
2009 1 1 16 10 0 84
2009 1 1 16 20 0 79
2009 1 1 16 30 0 75
2009 1 1 16 40 0 86
2009 1 1 16 50 0 79
2009 1 1 17 0 0 97
2009 1 1 17 10 0 84
2009 1 1 17 20 0 67
2009 1 1 17 30 0 72
2009 1 1 17 40 0 80
2009 1 1 17 50 0 89
2009 1 1 18 0 0 106
2009 1 1 18 10 0 21
2009 1 1 18 20 0 29
2009 1 1 18 30 0 320
2009 1 1 18 40 0 315
2009 1 1 18 50 0 319
2009 1 1 19 0 0 325
2009 1 1 19 10 0 323
2009 1 1 19 20 0 330
2009 1 1 19 30 0 332
2009 1 1 19 40 0 325
2009 1 1 19 50 0 328
2009 1 1 20 0 0 330
2009 1 1 20 10 0 328
2009 1 1 20 20 0 333
2009 1 1 20 30 0 331
2009 1 1 20 40 0 341
2009 1 1 20 50 0 338
2009 1 1 21 0 0 340
2009 1 1 21 10 0 341
2009 1 1 21 20 0 350
2009 1 1 21 30 0 348
2009 1 1 21 40 0 354
2009 1 1 21 50 0 350
2009 1 1 22 0 0 358
2009 1 1 22 10 0 353
2009 1 1 22 20 0 359
2009 1 1 22 30 0 354
2009 1 1 22 40 0 2
2009 1 1 22 50 0 8
2009 1 1 23 0 0 3
2009 1 1 23 10 0 14
2009 1 1 23 20 0 13
2009 1 1 23 30 0 15
2009 1 1 23 40 0 20
2009 1 1 23 50 0 17
It is necessary to conserve only the data recorded by the instrument exactly every three hours, as it is indicated below:
YEAR MONTH DAY HOUR MINUTE SECOND WIND DIRECTION (DEGREES)
2009 1 1 0 0 0 20
2009 1 1 3 0 0 27
2009 1 1 6 0 0 67
2009 1 1 9 0 0 104
2009 1 1 12 0 0 90
2009 1 1 15 0 0 92
2009 1 1 18 0 0 106
2009 1 1 21 0 0 340
Thanks in advance for your support!
Best,
Miguel
0 件のコメント
採用された回答
dpb
2017 年 2 月 21 日
編集済み: dpb
2017 年 2 月 22 日
For the data first posted--
ix=find([mod(wdir(:,4),3)==0 & wdir(:,5)==0]).'
ix =
1 19 37 55 73 91 109 127 145
>> wdirkeep=wdir(ix,:)
wdirkeep =
2009 1 1 0 0 0 20
2009 1 1 3 0 0 27
2009 1 1 6 0 0 67
2009 1 1 9 0 0 104
2009 1 1 12 0 0 90
2009 1 1 15 0 0 92
2009 1 1 18 0 0 106
2009 1 1 21 0 0 340
2009 1 2 0 0 0 25
>>
ADDENDUM
NB: To just do the selection, note that you don't need the find operation; that just returns the actual locations which is easier to read than the full-length logical vector. If simply need the result, then use the logical-addressing vector as
ix=(mod(wdir(:,4),3)==0 & wdir(:,5)==0).';
wdirkeep=wdir(ix,:);
or, unless there's reason to address this same subset again, there's no real reason to even make the temporary array at all (other than for legibility of code, I'll often write the indexing expression first as above and then do the substitution into the other function to keep parenthesis-nesting straight; writing it all in one pass can get to be too much to keep track of at one time)--
wdirkeep=wdir((mod(wdir(:,4),3)==0 & wdir(:,5)==0),:).';
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!