closest number to a treshold and greater than it

for example
i have
r1=0.9 r2=1.1 r3=1.2
i want to to know the r' that is nearest of 1 but greater than it.

回答 (2 件)

Image Analyst
Image Analyst 2013 年 7 月 8 日

0 投票

Is this homework? What have you tried? Have you tried subtracting 1 from the numbers and see which has the smallest difference greater than 0?
diff1 = r1-1;
diff2 = r2-1;
diff3 = r3-1;

1 件のコメント

Image Analyst
Image Analyst 2013 年 7 月 8 日
r = [0.8, 21.1, 3.9]; % Sample data
differences = r-1
differences(differences<0) = inf % Set <1 = to infinity.
[minValue, indexAtMin] = min(differences(differences>1))

サインインしてコメントする。

MEXICO
MEXICO 2013 年 7 月 8 日

0 投票

ok i didnt explain well. i have this vector that is changing every iteration
[r1 r2 r3]
this values are around 1, but im only interested in the nearest number to one but it have to be greAter than 1. the hole problem is like this
i have 3 equation that only are valid when the are greater than one and i have to choose the nearest to one.
the values of r1 only help me to know what f(r) i have to use, the f(r) that its r value is the nearest to 1 but greater than 1. i couldnt figure it out how to write it in matlab
any ideas guys?
r1 f(r1)=#$%%&( r1 f(r2)=#$%%&( r1 f(r3)=#$%%&(

1 件のコメント

Jan
Jan 2013 年 7 月 8 日
編集済み: Jan 2013 年 7 月 8 日
The last line is very cryptic. And please add all informations required to understand the question by editig the question, not by posting an answer. Thanks.

サインインしてコメントする。

質問済み:

2013 年 7 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by