Find the index of the first values in ascending array that are greater than each values from random array without for loop
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jérémy
am 26 Mär. 2018
Kommentiert: Jérémy
am 27 Mär. 2018
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 26 Mär. 2018
Second output of either histc or histcounts
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!