How to track indices of a matrix after a transformation
Afficher commentaires plus anciens
I have a mxn matrix A that is transformed in some way to formulate B. The transformation can either be simple rotation or some other combination of transformations like flipud(rot(A,90)) etc. I am looking for some way to track the indices of A after any such transformation.
For Example
A = [1 2 3; 4 5 6; 7 8 9]
B = rot(A,90) = [3 6 9;2 5 8;1 4 7]
Original_Index = [1 1;1 2;1 3;2 1;2 2;2 3;3 1;3 2;3 2] (Orginal_Index is a 9x2 matrix that contains the row col indices of entries of A in Row Raster manner)
Transformed_Index = [3 1;2 1;1 1;3 2;2 2;1 2;3 3;2 3;1 3] (Also a 9x2 matrix which stores the row col indices of the entries after transformation)
I would appreciate any help in this regard.
Réponse acceptée
Plus de réponses (2)
Azzi Abdelmalek
le 26 Mai 2013
A = [1 2 3; 4 5 6;7 8 9]
idx=1:numel(A) % the index of A
B=rot90(A);
idx1=reshape(idx,size(A))
new_idx=rot90(idx1);
new_idx=new_idx(:);
Benoit Espinola
le 4 Avr 2019
I had the same issue and cameup with this:
M = [1 2 3; 4 5 6; 7 8 9; 10 11 12];
m = reshape(M, numel(M),1);
x = reshape(repmat(1:size(M,1) ,size(M,2),1), numel(M),1);
y = reshape(repmat(1:size(M,2),size(M,1),1)', numel(M),1);
In my problem, I need to keep track of the original indices of the values in the original matrix (as they were keys for something else). Here x and y keep track of the original position, so m(1) was at position x(1) for columns and y(1) for rows.
I am sure there must be a better way to do it and I am not sure how this behaves in matrices with more dimensions.
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!