How to determine samplenumber for fixed distance-intervals?

2 visualizaciones (últimos 30 días)
Ot
Ot el 10 de Feb. de 2014
Comentada: Ot el 10 de Feb. de 2014
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!

Respuesta aceptada

Jos (10584)
Jos (10584) el 10 de Feb. de 2014
Editada: Jos (10584) el 10 de Feb. de 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 comentarios
Jos (10584)
Jos (10584) el 10 de Feb. de 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))
Ot
Ot el 10 de Feb. de 2014
Thanks!
It works

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Argument Definitions en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by