[Scilab-users] need a little help
P M
p.muehlmann at gmail.com
Fri Feb 15 21:46:04 CET 2019
Hi experts,
my problem is (I guess) a very common thing, but I somehow get stucked.
I aim to find the nearest position of ANY value in array_1 to ANY position
in array_2.
e.g.:
A = array of doubles with 1000 elements.
B = array of doubles with 10'000 elements.
for each element of A I want to know it's nearest value in B.
Also I want to know the index of the nearest value in B.
I could do it in a bunch of for-loops, but this is way to slow, since this
loops 1000 values against 10'000 values of B.
something like this:
nearesVal = zeros(1000);
distIndex = zeros(1000);
for i=1:1000
d = 1000000; // just a rediculous big number that is much greater than
max(A) & max(B)
for j = 1:10000
act_dist = abs( A(i) - B(j) ); // actual minimal distance
if act_dist <= d
d = act_dist;
nearestVal(i) = B(j);
distIndex(i) = j;
end
end
end
I do not have Scilab at hand, while I am writing this, but it looks like it
should work :-)
Thanks
Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20190215/9d706ee9/attachment.htm>
More information about the users
mailing list