フィルターのクリア

How to retrieve unique columns in a matrix ?

52 ビュー (過去 30 日間)
Sai Teja Suggala
Sai Teja Suggala 2022 年 3 月 10 日
コメント済み: Stephen23 2023 年 1 月 25 日
I would like to retrieve all the unique columns in a matrix..
If my matrix =
1 -1 1 1
1 1 1 1
2 1 1 1
UniqueColumns =
1 -1 1
1 1 1
2 1 1
Thank you before hand.

採用された回答

Stephen23
Stephen23 2022 年 3 月 10 日
編集済み: Stephen23 2022 年 3 月 10 日
A = [1,-1,1,1;1,1,1,1;2,1,1,1];
B = unique(A.','rows','stable').'
B = 3×3
1 -1 1 1 1 1 2 1 1
  2 件のコメント
Laxmikant Sharma
Laxmikant Sharma 2023 年 1 月 24 日
編集済み: Laxmikant Sharma 2023 年 1 月 24 日
What if you want the indeces too?
[B idx] = unique(A.', 'rows', 'stable').'
Not working!!!
Stephen23
Stephen23 2023 年 1 月 25 日
"What if you want the indeces too?"
A = [1,-1,1,1;1,1,1,1;2,1,1,1];
[B,idx] = unique(A.','rows','stable');
B = B.'
B = 3×3
1 -1 1 1 1 1 2 1 1
idx
idx = 3×1
1 2 3

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by