Single representation of same values in a Matrix

1 view (last 30 days)
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

Accepted Answer

Stephen23
Stephen23 on 24 Feb 2019
>> 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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!