Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

For loop and indexing help

조회 수: 5 (최근 30일)
Emma
Emma 2020년 2월 5일
마감: MATLAB Answer Bot 2021년 8월 20일
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
James Tursa
James Tursa 2020년 2월 5일
What have you done so far? What specific problems are you having with your code?
Emma
Emma 2020년 2월 5일
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.

답변 (1개)

Sindar
Sindar 2020년 2월 5일
check out the discretize function

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by