looking condition in matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
Hey,
I got matrix
[ 2 9841 5 4 2 1;
3 79463 1 3 1 0;
3 79463 4 3 1 0;
3 79463 5 3 1 0;
3 79463 1 3 2 0;
3 79463 4 3 2 0;
3 79463 5 3 2 0;
3 79463 1 4 1 0;
3 79463 4 4 1 0;
3 79463 5 4 1 0;
3 79463 1 4 2 0;
3 79463 4 4 2 0;
3 79463 5 4 2 0;
3 79463 1 4 1 1;
3 79463 4 4 1 1;
3 79463 5 4 1 1;
3 79463 4 4 1 1;
3 79463 5 4 1 1;
3 79212 1 3 1 0;]
I have to look for every row in column 1,2,4,5, if they match, then i check last column 6th, where is information if row data is correct or wrong.
If there are both correct and wrong data for rows that all include same values in column 1,2,4,5 than i must keep only correct data and erase wrong. If there is only wrong data for row than i keeep it.
The result should erase those two rows...
3 79463 4 4 1 0;
3 79463 5 4 1 0;
Thank you for your suggestions and solutions, take care.
Nejc
댓글 수: 4
Yao Li
2013년 4월 10일
Sorry, I haven't got it yet. Maybe you can take the first 5 rows for example. Pls. give the results for the first 5 rows.
답변 (1개)
Andrei Bobrov
2013년 4월 10일
편집: Andrei Bobrov
2013년 4월 10일
a = [ 2 9841 5 4 2 1;3 79463 1 3 1 0;3 79463 4 3 1 0;3 79463 5 3 1 0;3 79463 1 3 2 0;3 79463 4 3 2 0;3 79463 5 3 2 0;3 79463 1 4 1 0;3 79463 4 4 1 0;3 79463 5 4 1 0;3 79463 1 4 2 0;3 79463 4 4 2 0;3 79463 5 4 2 0;3 79463 1 4 1 1;3 79463 4 4 1 1;3 79463 5 4 1 1;3 79463 4 4 1 1;3 79463 5 4 1 1;3 79212 1 3 1 0;];
[~,~,ii] = unique(a(:,[1 2 4 5]),'rows');
i1 = histc(ii,1:max(ii));
out = a(ismember(ii,find(i1 > 1)) & a(:,end) == 1,:);
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Data Preparation에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!