Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

For loop and indexing help

5 vues (au cours des 30 derniers jours)
Emma
Emma le 5 Fév 2020
Clôturé : MATLAB Answer Bot le 20 Août 2021
I am generating a uniform random number using X=rand; I have a vector of values, say Z=[.1 .2 .3 .4 .5]. I have another vector,Y, of equal length to Z that is initiated with 0 values. Using a for loop, how can I compare the random number X to the values in Z to determine which values it falls between? For example, if X=.25, it would fall between .2 and .3. Then, Y(the index of the number that is closest to the random number), would be incremented by 1.
  2 commentaires
James Tursa
James Tursa le 5 Fév 2020
What have you done so far? What specific problems are you having with your code?
Emma
Emma le 5 Fév 2020
I am not sure what to do, I have been considering taking the differences between the values using a nested for loop but I ultimately do not know what is the most efficient method.

Réponses (1)

Sindar
Sindar le 5 Fév 2020
check out the discretize function

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by