finding duplicate number and adjacent row value
조회 수: 1 (최근 30일)
이전 댓글 표시
Suppose I have a matrix of values
v = [1 4; 1 5; 2 4; 2 4; 2 5; 2 5; 3 4; 3 7]
in column one the numbers are consecutive but with repetition, how can I find only the first numbers and corresponidng number in the other column, put them in a new matrix (v')? The new matrix should be like this from my example:
v'= [1 4; 2 4; 3 4]
I hope I am clear enough
Cheers
Sobhan
댓글 수: 1
Azzi Abdelmalek
2012년 9월 16일
편집: Azzi Abdelmalek
2012년 9월 16일
what if v= [1 4; 1 5; 2 4; 2 4; 2 5; 2 5; 3 4; 3 7;1 5;1 6]?
채택된 답변
Azzi Abdelmalek
2012년 9월 16일
v = [1 4; 1 5; 2 4; 2 4; 2 5; 2 5; 3 4; 3 7]
idx=diff(v(:,1))
v1=[];
if idx(1)==0
v1=[v1;v(1,:)]
end
for k=2:length(idx)
if idx(k)==0 & idx(k-1)~=0
v1=[v1; v(k,:)]
end
end
추가 답변 (1개)
Wayne King
2012년 9월 16일
편집: Wayne King
2012년 9월 16일
[~,iv] = unique(v(:,1),'stable');
vnew = v(iv,:);
댓글 수: 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!