MATLAB Answers

How can I match two vectors using the discrete inverse transform method?

1 view (last 30 days)
Tchilabalo on 3 May 2019
Commented: Tchilabalo on 4 May 2019
iV=reshape(pr,1,[]);% pr represents the pobability matrix
figure, cdfplot(prc)
I have a probability map (V) containing 4096 elements (see figure). I've also generated a vector U containing 100 random uniform probabilities. Now i want to match each elment of U to the correseponding probalility on the figure, using the discrete inverse transform method (Vj-1=<Ui<Vj). I'll apprecaite your help.


Sign in to comment.

Accepted Answer

darova on 3 May 2019
Give each element of U and compare with every element of V
ind = zeros(size(U));
for i = 1:length(U(:))
[~, ind(i)] = min( abs(U(i)-V) );
I think ismember() can be faster solution, but don't know how to apply it here


Show 1 older comment
Tchilabalo on 3 May 2019
Thanks Darova! It is what i was looking for. I have one follow up question. To get "V", i reshaped the probability matrix to a vector. Now how do I determine where the index are on the probability matrix.
darova on 3 May 2019
tol = 1000; % tolerance: 3 position after decimal point
[~, ind] = ismember( round(U(:)*tol),round(V(:)*tol) );
% V(:) - reshape matrix to vector
% U(i) == V(ind(i)) - (if ind(i) is not zero)
If you have linear index and want to convert it to [rows,columns]:
matrix_size = [m,n];
[I,J] = ind2sub(matrix_size,IND);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by