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

1 件のコメント

Huseyin Narci
Huseyin Narci 2013 年 11 月 22 日
yess..how can solve with matlab?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by