How to perform a lexicographical sorting of matrices

39 次查看(过去 30 天)
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 个评论
Sean de Wolski
Sean de Wolski 2013-2-14
Can you provide a small example of what you expect for the output?
Welcome to MATLAB and Answers!
sehreen
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
Matt J 2017-10-12
sortrows(reshape(k,4,[]).')

arun anoop m
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'

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by