how to reject of the next value less than the previous one

조회 수: 4 (최근 30일)
Offroad Jeep
Offroad Jeep 2016년 10월 23일
답변: Image Analyst 2016년 10월 23일
Hi to all the Matlab users, I have made a program in which I want to accept the value in a loop which is less than the previous one. Kindly advise. e.g. if first value at the start of the loop is 10 then next value comes 10.3 next 9.6..... I want that 10.3 should be rejected and 9.6 gets accepted and so on......... Kindly suggest..... Regards.....

채택된 답변

michio
michio 2016년 10월 23일
Not sure what you mean by reject, but will the following be of any help?
x=10;
while true
newvalue = 20*rand;
if newvalue > x
x = newvalue;
end
end

추가 답변 (1개)

Image Analyst
Image Analyst 2016년 10월 23일
You can try this:
value = 10;
oldValue = value;
maxIterations = 1000; % Failsafe
iteration = 1;
while value >= oldValue && iteration <= maxIterations
value = value + rand - 0.5 % Whatever...however you calculate a new value.
iteration = iteration + 1;
if value < oldValue
break;
end
oldValue = value;
end

카테고리

Help CenterFile Exchange에서 Elementary Math에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by