# Re: [Scilab-users] Extract closest value

```Hi Serge,

Thanks for the suggestion. I did find another method that also works via a
for-loop:
e.g.```
```
x=[1 2 3 4 5];y=[0 1.1 1.5 1.6 2.4 4.1 4.7 5 5.7];for k=1:length(x)
[val,idx]=min(abs(y-x(k)));
xx(k)=y(idx);end

Lester

On Thu, 2 Jun 2022 at 11:37, Steer Serge <serge.st...@laposte.net> wrote:

> If A and B are not too big you can proceed as follow:
> E=abs(ones(B')*A-B'*ones(A))
>
> [i,j]=ind2sub(find(E<=0.3),size(E));
> Serge
>
> Le 02/06/2022 à 10:17, Lester Anderson a écrit :
>
> Hi all,
>
> Is it possible to use one vector to find only those closest values in
> another vector with a tolerance limit?
>
> A=[2 3 4 5 6]; // source array
> B=[0.25 1.2 2.01 5.2 7.4 9.3 10.6 ]; // target array to find closest
> values to A
>
> So in the example above, the closest values would be 2.01 and 5.2 in B,
> all other values excluded. Arrays are not going to be the same size!
> Hopefully I have explained it well enough.
>
> Thanks
> Lester
>
>
> _______________________________________________
> users mailing
> listusers@lists.scilab.orghttp://lists.scilab.org/mailman/listinfo/users
>
>
>
```
```_______________________________________________
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users
```