query regarding while loop application

I have two vectors P and R of length 50 Vector P has values of a signal between 0 and 1 and R is a randomly generated vector with values between 0 and 1. Please help to write a code to check the following condition: if R(i)> p(kk) & R(i)<= p(kk+1) then store the value of (i) and move ahead to check the condition for next pair ; p(kk+1)and p(kk+2) else if the condition is not satisfied, then check the condition at next value of R. For e.g.
P=[0 0.0034 0.023 0.189];
R=[0.0004 0.234 0.023 0.011];
i=1, kk=1; j=1;
if R(i)> p(kk) & R(i)<= p(kk+1)
a(j)=i ; kk=kk+1;
else
i=i+1;
please please help

댓글 수: 4

Torsten
Torsten 2018년 5월 9일
Could you clarify the condition " P(i)<=R >= P(i+1)" ? I don't understand what you mean.
Jan
Jan 2018년 5월 9일
@stud: Please edit the question and append a short and relevant example of an input and the wanted output.
stud
stud 2018년 5월 10일
편집: per isakson 2018년 5월 10일
P=[0 0.0034 0.023 0.189];
R=[0.0004 0.234 0.023 0.011];
i=1, kk=1; a=[];
if R(i)> p(kk) & R(i)<= p(kk+1) i.e.
R(1)>=P(1) & R(1)<P(2)
then store the value of i in a[] otherwise move to R(2). To verify the condition for every consecutive pair of p, i is initialized to 1. I hope i have made my point clear. Regards
stud
stud 2018년 5월 10일
편집: Walter Roberson 2018년 5월 10일
Let,
P=[0 0.0034 0.023 0.189];
R=[0.0004 0.234 0.023 0.011];
i=1, kk=1;
if R(i)> p(kk) & R(i)<= p(kk+1)
then store the value of (i) in some variable and then move to check the condition for next pair of p i.e. between p(kk+1)and p(kk+2) else if the condition is not satisfied, then increment the value of i, to get next value of R.

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2018년 5월 9일

0 개 추천

I think what you want is the discretize function, though the fact that both your bin edges in your problem statement use <= is a problem. If an element of R is exactly equal to one of the elements of P, do you want the element in R to be considered in the left bin or the right bin?
R = 0.25;
P = [0 0.25 0.5 0.75 1];
Should R be in the bin [0, 0.25] or the bin [0.25, 0.5]?
If you only want one of the endpoints to be included in a bin, use the 'IncludedEdge' option to specify which one.

댓글 수: 1

stud
stud 2018년 5월 10일
Sorry, the =sign is with the lower limit only... and R is of the same size as P

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2018년 5월 9일

편집:

2018년 5월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by