<div dir="ltr">Hi Ncl user,<div><br><div>I would like to implement the closest value function without using ind function. I would appreciate any suggestion. </div></div><div>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">value2check = </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">18.382</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">array2check = (/</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">18.0001</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> ,</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">18.5888</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">, </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">18.01</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">, </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">18.5</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">/)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">index <span class="gmail-Apple-converted-space"> </span>= closest_val(value2check,array2check)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">print(index)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">xAbsDif = abs(value2check-array2check)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">xMinVal = min(xAbsDif)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">iClose<span class="gmail-Apple-converted-space"> </span>= (ind(xAbsDif.eq.xMinVal))</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">print(iClose)</span></p><p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">:::::without using ind;;;;;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(175,173,36)">do</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> i=</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">0</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">3</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(175,173,36)">if</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> any(xAbsDif(i)) .eq. any(xMinVal) </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(175,173,36)">then</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">print<span style="background-color:rgb(0,166,178)">(i) ;; it's not giving right answer</span></span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(175,173,36)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">end</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">if</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(175,173,36)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">end</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">do</span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(175,173,36)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(175,173,36)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">Thanks</span></p></div></div>