필터 지우기
필터 지우기

How to determine samplenumber for fixed distance-intervals?

조회 수: 1 (최근 30일)
Ot
Ot 2014년 2월 10일
댓글: Ot 2014년 2월 10일
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))
Ot
Ot 2014년 2월 10일
Thanks!
It works

댓글을 달려면 로그인하십시오.

추가 답변 (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