Find the index of the first values in ascending array that are greater than each values from random array without for loop

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de Mzo. de 2018
Second output of either histc or histcounts
  3 comentarios

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by