Single representation of same values in a Matrix

1 回表示 (過去 30 日間)
Jason
Jason 2019 年 2 月 24 日
コメント済み: Jason 2019 年 2 月 24 日
Hello.
I have matrix A:
5.00 5.00 3.00 3.00 4.00 4.00
5.00 5.00 3.00 3.00 4.00 4.00
2.00 2.00 1.00 1.00 5.00 5.00
I need to replace all the same valus with a unique value so the matrix I need is:
5 3 4
2 1 5
Any suggestions please

採用された回答

Stephen23
Stephen23 2019 年 2 月 24 日
>> M = [5,5,3,3,4,4;5,5,3,3,4,4;2,2,1,1,5,5]
M =
5 5 3 3 4 4
5 5 3 3 4 4
2 2 1 1 5 5
>> S = size(M);
>> X = [true(1,S(2));diff(M,1,1)] & [true(S(1),1),diff(M,1,2)];
>> V = sum(X,1);
>> Z = reshape(M(X),V(find(V,1)),[])
Z =
5 3 4
2 1 5

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by