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)
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Mär. 2018
Second output of either histc or histcounts
  3 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

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!

Translated by