Going back to original matrix
Afficher commentaires plus anciens
Hello,
I have a matrix that is 3x2 A= [1 1; 1 2; 2 2];
I also have a vector B that is nx1 (assume n equals to 27) this vector has three possible values 1, 2, 3.
When I apply Z= A(B,:) I get a matrix nx2 where the number one in vector B was changed for 1 1, the number 2 by 1 2 and the number 3 by 2 2.
Then I have a matrix L that is in the same format as Z i.e. is an nx2 matrix with values 1 1, 1 2 or 2 2 for each row.
Is there anyway to transform this matrix L into the same form as vector B? i.e. change 1 1 for 1, 1 2 for 2 and 2 2 for 3?
The matrix A is an specific case of a general formula as is the vector B. Thus, I need a way to have the format of B when I have a matrix in the format of A without hard coding it for instance with a conditional specifiying that 1 1 equals 1; 1 2 equals 2 and 2 2 equals 3
Thank you very much
Réponse acceptée
Plus de réponses (1)
David Hill
le 13 Août 2020
b=zeros(size(B));
for k=1:length(A)
b(ismember(L,A(k,:),'rows'))=k;
end
Catégories
En savoir plus sur Logical 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!