# How to perform a lexicographical sorting of matrices

조회 수: 54(최근 30일)
Bob 2013년 2월 14일
답변: arun anoop m 2019년 9월 20일
Hi people, i'm new to this MATLAB and as of now i'm currently working copy-move forgery detection. I've stored my matrices into a multidimensional array but i'm quite clueless as to how do i go about sorting it. Below is a testing code which im playing around with:
a=[1 2 3 4 5;6 7 8 9 1;1 2 3 4 5;6 7 4 2 6;2 3 8 9 1]
k = zeros([2, 2, 16], class(a));
currSliceNo = 0;
for i=1:4
for j=1:4
currSliceNo = currSliceNo+1;
k(:,:,currSliceNo)=(a(i:i+1,j:j+1));
end
end
k
Where k is my multidimensional array which i would like to do a lexicographical sort on. Any help would be appreciated thank you :)
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
sehreen 2014년 2월 11일
Hi Bob i think you are using block based method to detect copy move forgry and for that u might have divided the image into overlapping blocks and perform certain transformation on each block..can you please tell me how you have done it and send me your code sample...i will be very thankful to you.

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

### 답변(2개)

Matt J 2017년 10월 12일
sortrows(reshape(k,4,[]).')
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

arun anoop m 2019년 9월 20일
Explanation: Dictionary Sort
Filenames and file extensions are separated by the extension separator: the period character '.'. Using a normal SORT the period gets sorted after all of the characters from 0 to 45 (including !"#\$%&'()*+,-, the space character, and all of the control characters, e.g. newlines, tabs, etc). This means that a naive natural-order sort will sort some short filenames after longer filenames. In order to provide the correct dictionary sort, with shorter filenames first, NATSORTFILES splits filenames from file extensions and sorts them separately:
D = {'test_ccc.m'; 'test-aaa.m'; 'test.m'; 'test.bbb.m'};
sort(D) % '-' sorts before '.'
natsort(D) % '-' sorts before '.'
natsortfiles(D) % correct dictionary sort
ans =
'test-aaa.m'
'test.bbb.m'
'test.m'
'test_ccc.m'
ans =
'test-aaa.m'
'test.bbb.m'
'test.m'
'test_ccc.m'
ans =
'test.m'
'test-aaa.m'
'test.bbb.m'
'test_ccc.m'

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

### 범주

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by