Deleting sequence of igual values from a matrix

1 回表示 (過去 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 Center および File ExchangeMatrix and Vector Construction についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by