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

1 回表示 (過去 30 日間)
Tchilabalo
Tchilabalo 2019 年 5 月 3 日
コメント済み: Tchilabalo 2019 年 5 月 4 日
iV=reshape(pr,1,[]);% pr represents the pobability matrix
V=cumsum(V)/sum(V);
figure, cdfplot(prc)
U=rand(1,100)
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.

採用された回答

darova
darova 2019 年 5 月 3 日
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) );
end
I think ismember() can be faster solution, but don't know how to apply it here
  4 件のコメント
darova
darova 2019 年 5 月 3 日
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);
Tchilabalo
Tchilabalo 2019 年 5 月 4 日
Thanks for your help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by