Find the index of the first values in ascending array that are greater than each values from random array without for loop
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have a random vector A=rand(n,1) and a given vector B(n,1) which is sorted in ascending values. I want to find the index of the first value of A that is greater than each values of my random vector. For example with:
A = [1 ; 6 ; 2 ; 8 ; 3]; B = [2 ; 4 ; 6 ; 8 ;10];
It would give: indexes = [1 4 2 5 2].
My current solution consist of using a for loop:
ix = zeros(N,1);
for i = 1:N
r = rand;
ix(i) = find(B>A,1);
end
I would like to be able to do the same without using a for loop in order to increase the speed of the operation.
Thanks
0 commentaires
Réponse acceptée
Walter Roberson
le 26 Mar 2018
Second output of either histc or histcounts
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!