ImageAnalyst <imageanalyst@mailinator.com> wrote in message <650a8138-e16c-4608-b391-d1e08ee7903b@v17g2000yqv.googlegroups.com>...
> Well of course we can think of some code to handle this case (just as
> I'm sure you can), but I'm not sure what elements go where for higher
> dimensions. Could you also give an example for a 6 by 6 matrix or a
> 10 by 10 matrix?
Try this code... It is basically sorting the matrix entries in to lexicographically order.
%1 2 3 4
%5 6 7 8
%11 55 1 2
%45 1 5 6
index = 1;
A = [1 2 3 4;5 6 7 8;11 5 1 2;45 1 5 6]
B = zeros(4,4);
for i = 1:2:4
for j = 1:2:4
C = A(i:i+1,j:j+1)'
reshape(C,1,4)
B(index,:) = reshape(C,1,4)
index = index +1;
end
end
B
%1 2 5 6
%3 4 7 8
%11 55 45 1
%1 2 5 6
[B index] = sortrows(B)
% 1 2 5 6
% 1 2 5 6
% 3 4 7 8
% 11 5 45 1
> Well of course we can think of some code to handle this case (just as
> I'm sure you can), but I'm not sure what elements go where for higher
> dimensions. Could you also give an example for a 6 by 6 matrix or a
> 10 by 10 matrix?
Try this code... It is basically sorting the matrix entries in to lexicographically order.
%1 2 3 4
%5 6 7 8
%11 55 1 2
%45 1 5 6
index = 1;
A = [1 2 3 4;5 6 7 8;11 5 1 2;45 1 5 6]
B = zeros(4,4);
for i = 1:2:4
for j = 1:2:4
C = A(i:i+1,j:j+1)'
reshape(C,1,4)
B(index,:) = reshape(C,1,4)
index = index +1;
end
end
B
%1 2 5 6
%3 4 7 8
%11 55 45 1
%1 2 5 6
[B index] = sortrows(B)
% 1 2 5 6
% 1 2 5 6
% 3 4 7 8
% 11 5 45 1