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

Yash
Yash 2013년 11월 21일
what sorting algo are you looking for?

댓글을 달려면 로그인하십시오.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 11월 19일

0 개 추천

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

Huseyin Narci
Huseyin Narci 2013년 11월 19일
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 2013년 11월 19일
Please give an example and show the expected result
Huseyin Narci
Huseyin Narci 2013년 11월 19일
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..

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 11월 21일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2013년 11월 19일

댓글:

2013년 11월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by