Using unique command in a matrix

Dear all, I would like to delete the columns of a matrix according to the unique values of its row. More specifically: Suppose to have this matrix: A =
1 2 3 3 3 5 6
11 14 16 16 16 14 16
I would like to select the unique values of the first row: [1 2 3 5 6] and create the matrix: A =
1 2 3 5 6
11 14 16 14 16
Anyone who can help me?

1 件のコメント

Matt J
Matt J 2016 年 2 月 10 日
Your result is unambiguous only because in your example, the replicates of '3' in the first row coincide with replicates of '16' in the second row. What if the original matrix looks like this:
1 2 3 3 3 5 6
11 14 16 17 18 14 16
What goes under the '3' in the result? Will it be 16, 17, or 18?

サインインしてコメントする。

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 2 月 10 日
編集済み: Azzi Abdelmalek 2016 年 2 月 10 日

0 投票

A=[1 2 3 3 3 5 6
11 14 16 16 16 14 16]
B=unique(A','rows')'
Or maybe you want this
[ ~,jj]=unique(A(1,:))
B=A(:,jj)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2016 年 2 月 10 日

編集済み:

2016 年 2 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by