HOW TO MOVE THE ELEMENTS BACK IN ORDER IN MATRICS WHICH ARE BEEN MOVED DIAGONALLY
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
1 4 6 8 2 3 7 9 5
all elements are move diagonally one pixel for m*n matix WHEN APPLYING THE FOLLOWING CODE
I = [
1 4 6
8 2 3
7 9 5]; % initial array
idx = reshape(1:numel(I),size(I));
for jj = -size(I,1) + 2 : size(I,2) - 2
a = diag(idx,jj);
I(a) = I(circshift(a,1));
end
example output
2 3 6
9 5 4
7 8 1
HOW TO GET THE ORIGINAL RESULT TO SHIFT DIAGONALLY . THE EXAMPLE OUTPUT IS
1 4 6 8 2 3 7 9 5
0 comentarios
Respuesta aceptada
Matt Fig
el 25 de Sept. de 2012
Are you asking how to undo what your code does?
for jj = -size(I,1) + 2 : size(I,2) - 2
a = diag(idx,jj);
I(a) = I(circshift(a,-1)); % Note the -1
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Operating on Diagonal Matrices 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!