Search value that is nearest to the multiple of a specific value
Afficher commentaires plus anciens
Hi everybody,
I have the following problem. I did a measurement with a distance sensor on a car, which recordes the distance between sensor and pavement. It measures with 12,5 kHz. Another tool measured the distance travelled with the vehicle. Now i have two vectors: 1) a vehicle distance vector A with 595875x1 entries 2) a height distance vector B measured by the sensor with 595875x1 entries. The vectors have the same lenght.
Now whit I want to do is the following:
The vehicle distance vector has enties such as: 0.0012, 0.0015, 0.0019 [m] etc. But I only want the entries every 0.1 m, eg. 0.1, 0.2, 0.3 and so on. Given that the exact value of 0.1 and so on doesn't exist, but only 0.1002, 0.2004 and so on I need a function that gives me the nearest value to every multiple of 0.1, so every 10 cm. All the other entries should be deleted.
The goal ist to find the corresponding height distance value for every 10 cm. At the end the vectors should be the same lenght. I attached a pic of what i wanted to explain.
I tried the function interp1 with the method 'nearest' but it does not work.
Perhaps anybody can help. If there is someone who speaks german it would be easier for me to explain because my english is not soo good. I hope you understand my problem.
regards Pasqua

Sensor_D1 is the vehicle distance vector and Ar700_1 is the height distance vector.
2 commentaires
Jan
le 22 Sep 2015
Please do not crosspost. Posting a question in different forums waste the time of the voluntary helpers, if the create an answer which has been given in the other forum before. If you have really good reasons to post a question twice, add a link to the other forum in both questions. Thanks.
Réponses (2)
Walter Roberson
le 22 Sep 2015
idx = interp1(distance, 1:length(distance), 0.1: 0.1 :LastValue, 'nearest')
Now distance(idx) is the values you want to keep
dist2 = 0.1:0.1:max(dist);
for i = 1:numel(dist2), [~, ind(i)] = min(abs(dist - dist2(i))); end
height2 = height(ind);
Catégories
En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!