How to determine samplenumber for fixed distance-intervals?

1 次查看(过去 30 天)
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!

采纳的回答

Jos (10584)
Jos (10584) 2014-2-10
编辑:Jos (10584) 2014-2-10
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 个评论
Jos (10584)
Jos (10584) 2014-2-10
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))

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Reaction Engineering 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by