MATLAB: Error using unique command

MATLABsortunique

I have two values
A = [1000 16000 100000 30000 2000]
B = [150 100 4000 5000 2000];
I used code below to get the Sorted value of B according to A:
[ii jj k] = unique(A);
B = unique(B);
P = B(k);
C = [100 4000 2000 5000 150];
If my values of A are from -400 to 400 and and values of B are from -100 to 100 I get the error :
Index exceeds Dimension
Please provide assistance.

Best Answer

Edited
A=[1000 16000 100000 30000 2000]
B=[150 100 4000 5000 2000];
[~,idx]=sort(A)
[~,idx1]=sort(idx)
C=B(idx1)