Delete rows based on column value

15 ビュー (過去 30 日間)
David du Preez
David du Preez 2017 年 4 月 10 日
編集済み: Andrei Bobrov 2017 年 4 月 10 日
Hi. I have a 8761x14 matrix. I wanted to consider the first 24 rows as I have hourly data. If all the values in column 8 are zero (ie. 24 zeros) I want to delete all 24 rows and then repeat this considering every 24 rows.

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 4 月 10 日
編集済み: Andrei Bobrov 2017 年 4 月 10 日
Let A - your matrix [8761 x 14]
[m,n] = size(A);
A1 = [A; nan(mod(-m,24),n)];
A1 = reshape(A1',n,24,[]);
Aout = A1(:,:,any(A1(8,:,:) ~= 0,2));
Aout = reshape(Aout,n,[])';
or
m = size(A,1);
i0 = ceil((1:m)'/24);
Aout = A(repelem(accumarray(i0,A(:,8)) ~= 0,accumarray(i0,1)),:);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by