it will be a random matrix 3x3.For example=[7 5 1][8 9 2][3 5] One field is empty.I need use sorting algorithm.Looks like=[1 2 3][4 5 6][7 8 ] Empty field will be final.

1 comentario

Yash
Yash el 21 de Nov. de 2013
what sorting algo are you looking for?

Iniciar sesión para comentar.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 19 de Nov. de 2013

0 votos

A={[7 5 1],[8 9 2],[3 5]}
idx2=cumsum(cellfun(@numel,A));
idx1=[1 idx2(1:end-1)+1];
C=sort(cell2mat(A));
out=arrayfun(@(ii1,ii2) C(ii1:ii2),idx1,idx2,'un',0);
celldisp(out)

3 comentarios

Huseyin Narci
Huseyin Narci el 19 de Nov. de 2013
thank you for answer.so other question.numbers move on empty field but do not cross,only forward,back,down up..How can solve this problem?
Azzi Abdelmalek
Azzi Abdelmalek el 19 de Nov. de 2013
Please give an example and show the expected result
Huseyin Narci
Huseyin Narci el 19 de Nov. de 2013
still 3x3 random matrix for example:
[3 5 8]
[1 _ 4]
[6 7 2] _(empty field) numbers move on empty field but do not cross,only forward,back,down and up..
expected result still same :
[1 2 3]
[4 5 6]
[7 8 _]
it is a kind of game..

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 21 de Nov. de 2013

0 votos

Sounds to me like you are dealing with the 8 Puzzle; http://en.wikipedia.org/wiki/15_puzzle

Categorías

Preguntada:

el 19 de Nov. de 2013

Comentada:

el 22 de Nov. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by