Filter löschen
Filter löschen

How to determine samplenumber for fixed distance-intervals?

1 Ansicht (letzte 30 Tage)
Ot
Ot am 10 Feb. 2014
Kommentiert: Ot am 10 Feb. 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!

Akzeptierte Antwort

Jos (10584)
Jos (10584) am 10 Feb. 2014
Bearbeitet: Jos (10584) am 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 Kommentare
Jos (10584)
Jos (10584) am 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))
Ot
Ot am 10 Feb. 2014
Thanks!
It works

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Reaction Engineering finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by