Single representation of same values in a Matrix

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by