How to perform a lexicographical sorting of matrices
13 views (last 30 days)
Show older comments
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 Comments
Sean de Wolski
on 14 Feb 2013
Can you provide a small example of what you expect for the output?
Welcome to MATLAB and Answers!
sehreen
on 11 Feb 2014
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.
Answers (2)
arun anoop m
on 20 Sep 2019
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'
0 Comments
See Also
Categories
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!