Filter out nonzero number in array of n*2 dimension.

3 ビュー (過去 30 日間)
Chiranjibi
Chiranjibi 2014 年 7 月 16 日
コメント済み: Joseph Cheng 2014 年 7 月 16 日
I have two column and 208k rows array, each row is event number. My array is like that,
3145728 0
0 3
0 3
0 3
3145728 0
0 192
0 0
384 0
48 0
3145728 0
3145728 0
0 384
0 3
2097152 0
0 3
3145728 0
0 3
0 3
0 3
16777216 0
This is only for 20 events.Here, it look like randomly numbered of zero and non zero(i.e one row non zero and other row zero and vice-versa for each event). So can anybody please give me idea that how to filter out if there are non zero numbers in the same row of both column through matlab script.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 16 日
A(all(A,2),:)

その他の回答 (2 件)

James Tursa
James Tursa 2014 年 7 月 16 日
If I understand your question, you want to delete the rows with non-zero entries in both columns, e.g.,
idx = sum(A~=0,2)==2;
A(idx,:) = [];
  6 件のコメント
Chiranjibi
Chiranjibi 2014 年 7 月 16 日
Keep row where both don't equal zero. These must be in same rows of both column.
Joseph Cheng
Joseph Cheng 2014 年 7 月 16 日
then just modify what James supplied. As you can see he first finds the index where there are non zeros in both.
So we can change it to
ind = sum(A,2)==0;
which will each column to each other. Check if rows equal zero and now we have which ones are equal to zero.
Then we can do A(ind,:)=[] which will get rid of all rows which add up to zero.

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


Daniel
Daniel 2014 年 7 月 16 日
matrix = [3145728,0;...
0,3;...
0,3;...
0,3;...
3145728,0;...
0,192;...
0,0;...
384,0;...
48,0;...
3145728,0;...
3145728,0;...
0,384;...
0,3;...
2097152,0;...
0,3;...
3145728,0;...
0,3;...
0,3;...
0,3;...
16777216,0];
Indices = matrix(:,1) ~= 0 | matrix(:,2) ~= 0;
matrix = matrix(Indices,:);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by