Single representation of same values in a Matrix

1 visualización (últimos 30 días)
Jason
Jason el 24 de Feb. de 2019
Comentada: Jason el 24 de Feb. de 2019
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

Respuesta aceptada

Stephen23
Stephen23 el 24 de Feb. de 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

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by