필터 지우기
필터 지우기

How do i find rows that contain duplicate values only?

조회 수: 3 (최근 30일)
flemingtb
flemingtb 2018년 5월 10일
편집: OCDER 2018년 5월 10일
for example i want to identify the row and column that contain "3" only and delete them from the data
x = [1 3 5 6; 2 3 6 4; 9 3 9 6; 3 3 3 3]

채택된 답변

OCDER
OCDER 2018년 5월 10일
x = [1 3 5 6; 2 3 6 4; 9 3 9 6; 3 3 3 3; 1 3 3 4]
B = (x == 3);
DelCol = sum(B, 1) == size(B, 1);
DelRow = sum(B, 2) == size(B, 2);
x(:, DelCol) = [];
x(DelRow, :) = [];
  댓글 수: 2
flemingtb
flemingtb 2018년 5월 10일
This works but i'm struggling to understand why. Can you explain the code in line '3' and '4'?
OCDER
OCDER 2018년 5월 10일
편집: OCDER 2018년 5월 10일
B = (x == 3) returns a matrix. 1 is where x == 3
0 1 0 0
0 1 0 0
0 1 0 0
1 1 1 1
0 1 1 0
DelCol = sum(B, 1) == size(B, 1); Takes the sum of B downward along the row, then finds where the sum == the number of rows.
EX: If there are 5 3's and 5 rows, then that column is all 3's.
0 1 0 0
DelRow = sum(B, 2) == size(B, 2); same as above, but this find which rows are all 3's.
0
0
0
1
0
x(:, DelCol) = []; %Delete all columns where DelCol is 1
x(DelRow, :) = []; %Delete all rows where DelRow is 1

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Author Block Masks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by