Deleting sequence of igual values from a matrix

조회 수: 6 (최근 30일)
Felipe vielmo
Felipe vielmo 2017년 9월 10일
댓글: Felipe vielmo 2017년 9월 11일
Hello there,
I have a matrix with a sequence of numbers, as it referes to a conjunction of points coordenates, most of times this values became monotonous in one of the lines, I want to discart every point that do not change em both lines 1 and 2 at the same time. Example:
[0 0 0 1 1 1 2 2 2 3 3 3,
0 1 2 2 3 4 5 6 7 8 9 10]
I just want to select
[0 1 2 3,
0 2 5 8]

채택된 답변

Jose Marques
Jose Marques 2017년 9월 11일
Hello Felipe. Try this:
A = [0 0 0 1 1 1 2 2 2 3 3 3,
0 1 2 2 3 4 5 6 7 8 9 10];
[C, ia, ic] = unique(A(1,:));
C = vertcat(C,A(2,ia));
The function "unique" returns the unique values in a array.
  댓글 수: 1
Felipe vielmo
Felipe vielmo 2017년 9월 11일
Exactly the answer that I needed, thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix and Vector Construction에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by