Search value that is nearest to the multiple of a specific value

1 view (last 30 days)
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 Comments
Jan
Jan on 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.
Pasquali
Pasquali on 22 Sep 2015
Edited: Pasquali on 22 Sep 2015
Ok thank you, didn' know that. Won't happen again.
Jan Simon, any other suggestions for solving my problem?

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 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

Thorsten
Thorsten on 22 Sep 2015
Edited: Thorsten on 22 Sep 2015
dist2 = 0.1:0.1:max(dist);
for i = 1:numel(dist2), [~, ind(i)] = min(abs(dist - dist2(i))); end
height2 = height(ind);
  2 Comments
Thorsten
Thorsten on 22 Sep 2015
Edited: Thorsten on 22 Sep 2015
height is the height distance vector B, and height2 are the desired height values corresponding to the distance values closest to 0.1, 0.2, etc, whose indices are stored in ind.

Sign in to comment.

Categories

Find more on Control System Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!