How to determine samplenumber for fixed distance-intervals?
2 views (last 30 days)
Show older comments
I have a Matrix [1 x 70764] that displays total distance (m) covered up until that point.
I want to determine at which samples intervals of 0.5 m are covered for the whole Matrix.
I want to get an output S which displays the samplenumber at which these 0.5 meter intervals have been covered.
So S(1) = 1 --> total distance is 0 S(2) = ? --> total distance is 0.5 S(3) = ? --> total distance is 1
etc. etc.
Thanks a lot already!
0 Comments
Accepted Answer
Jos (10584)
on 10 Feb 2014
Edited: Jos (10584)
on 10 Feb 2014
For examples, I prefer integers, so I upscaled everything by a factor 10.
% your data
M = [0 1 4 6 8 10 12 14 16 17 18 19 22 23] % cumulative distance covered
D = 5 ; % distance
% Note that M is strictly monotonically increasing
Index = 1:numel(M) ;
P = D:D:M(end)
S = interp1(M, Index, P) % S(k) would be where we expected P(k) to appear in M
S = ceil(S) % After (or at) point S(k) we have covered k*D meters or more
3 Comments
Jos (10584)
on 10 Feb 2014
In that case M is not strictly monotonically increasing, causing problems for INTERP1. However, you can safely remove those values.
M = [0 1 4 6 8 8 8 8 8 8 8 8 10 12 14 16]
D = 5
P = D:D:M(end)
Index = 1:numel(M)
dM = diff(M)
q = [true dM>0] % include first distance always
M(q) % just to show the used ...
Index(q) % ... values for interp1
S = ceil(interp1(M(q), Index(q), P))
More Answers (0)
See Also
Categories
Find more on Argument Definitions 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!