MATLAB: How to call vector in matrix with condition

.

Let's say:
A=[7 2 3 50;4 5 6 15;1 8 9 20;1 1 1 30]
A= 7 2 3 50
4 5 6 15
1 8 9 20
1 9 8 30
B=[1; 7]
B=[1
7]
Question: I wanna call only vector in column 4 of matrix A with the condition is: the value of matrix B have the same value of vector in 1st column of matrix A?
I hope the result like that:
result=[20; 30;50]
result=[20
30
50]
i try :
result=A(ismember(A(:,1),B,'rows'),4);
But, result=[50; 20;30]% it is not in order of vector in matrix B ????

Best Answer

[tf,loc] = ismember(A(:,1),B);
r = sortrows([loc(tf),A(tf,4)],1);
r(:,2)
ans =
20
30
50