How can already used elements be eliminated one by one in 2D matrix while moving upwards? | Efficienlty
Mostrar comentarios más antiguos
Input
input = [1 2 0;
2 3 4;
4 5 6];
Output
Output= [1 0 0;
2 3 0;
4 5 6];
Why efficiently : For inputting a big matrix of say 360000 x 36.
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 3 de Nov. de 2018
Use unique():
inputMatrix = [1 2 0;
2 3 4;
4 5 6]
[~, ia, ic] = unique(inputMatrix);
output = zeros(size(inputMatrix)); % Initialize
output(ia) = inputMatrix(ia)
4 comentarios
JAI PRAKASH
el 3 de Nov. de 2018
James Tursa
el 3 de Nov. de 2018
So it appears you have added an additional requirement, that of moving elements to the left. Are there any other requirements that you haven't told us about?
Walter Roberson
el 3 de Nov. de 2018
That output contradicts the original pattern. For that "should be" output to be true, then the output for
input = [1 2 0;
2 3 4;
4 5 6];
should be
[1 2 0;
3 4 0;
5 6 0;]
JAI PRAKASH
el 3 de Nov. de 2018
Editada: JAI PRAKASH
el 3 de Nov. de 2018
Categorías
Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!