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

 Accepted Answer

[~,B] = ismember(L,A,'rows')

More Answers (1)

b=zeros(size(B));
for k=1:length(A)
b(ismember(L,A(k,:),'rows'))=k;
end

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!