How to select the combinations without repetitions in a matrix?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Adam Silva
el 1 de Feb. de 2014
Comentada: Azzi Abdelmalek
el 1 de Feb. de 2014
Hi Everybody,
I have a question regarding matrix sorting. I have a matrix "A" a 6 by 2 matrix.
A=[
1 2
3 2
1 2
2 1
1 4
2 5];
As you can see row 1,3 and 4 have the same answer but inter changed numbers. How do we get matrix "B" without any combination repeats. Thank you
4 comentarios
Image Analyst
el 1 de Feb. de 2014
Azzi's code should do it then, since you want to take the first occurrence , regardless of the order of the columns. WARNING: If you have floating point numbers and not integers, be aware of the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Respuesta aceptada
Azzi Abdelmalek
el 1 de Feb. de 2014
Editada: Azzi Abdelmalek
el 1 de Feb. de 2014
[ii,jj]=unique(sort(A,2),'rows','stable')
B=A(jj,:)
3 comentarios
Azzi Abdelmalek
el 1 de Feb. de 2014
Then use
[ii,jj]=unique(sort(A,2),'rows')
B=A(jj,:)
Azzi Abdelmalek
el 1 de Feb. de 2014
Shape commented
Ok got it. I removed the option 'stable'.
Thank you
Más respuestas (0)
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!