How to perform a lexicographical sorting of matrices

28 visualizaciones (últimos 30 días)
Bob
Bob el 14 de Feb. de 2013
Respondida: arun anoop m el 20 de Sept. de 2019
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 comentarios
Sean de Wolski
Sean de Wolski el 14 de Feb. de 2013
Can you provide a small example of what you expect for the output?
Welcome to MATLAB and Answers!
sehreen
sehreen el 11 de Feb. de 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.

Iniciar sesión para comentar.

Respuestas (2)

Matt J
Matt J el 12 de Oct. de 2017
sortrows(reshape(k,4,[]).')

arun anoop m
arun anoop m el 20 de Sept. de 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'

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by