Finding consecutive number and only keeping the nearest to a number
Afficher commentaires plus anciens
Hello,
I got some data from a robot movement and now I want to find the nearest of the consecutive numbers to the number 389.387. This is my code so far, but I have no idea how to do the "closest to 389.387" loop. Sadly, there is no point with 389.387, so I can't just search for this number... Look at the picture attached, the red circled area is where the numbers near 389.387 are. I'm grateful for your ideas!

for i = 1:length(z_irl)
if z_irl(i) > 389.2 && z_irl(i) < 389.5 % z_irl is the whole robot movement and I tried to only keep the
% numbers near 389.387
y_temp_r(i) = z_irl(i);
end
%y_temp(i) = 0;
end
[row_r,col_r,value_r]=find(y_temp_r); %with this line I get all the information needed of the numbers near 389.387
smallnr = zeros(1,b); %b is 10, there should only be 10 Numbers near 389.387
for i = 1:length(row_r)
difference(i) = abs(value_r(i) - 389.387);
end
i = 2;
if diff(row_r)==1 %and this is where I don't know how to continue, I dont know how to
%do a <> query only for the consecutive numbers, it's
if difference(i-1) < difference(i) %driving me insane (ノಠ益ಠ)ノ彡┻━┻ and I think i need two counters,
%one for counting the line of the smallest number and one for counting
smallnumber(i-1) = difference(i-1); %the number of the consecutive number
else
smallnumber(i-1) = difference(i);
end
i = i + 1;
end
I'm using Matlab R2020b for academic use.
Réponse acceptée
Plus de réponses (1)
Bruce Rogers
le 7 Juin 2021
Modifié(e) : Bruce Rogers
le 7 Juin 2021
Catégories
En savoir plus sur Time-Frequency Analysis dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

