Data sorting and logical expressions

조회 수: 7 (최근 30일)
Asher
Asher 2019년 5월 29일
댓글: Asher 2019년 6월 2일
Hi!
I have a speed vector from a vehicle where i want to identify the stops and how long they are. I managed to create several logic vectors which save the position (index) or mark the index as "0" else "1". However, the logic vector I went with is one which save the vector index if the speed is zero or very close to. Resulting if there´s a longer stop, the index count will be something such as [0;0;0;33;34;35;...;99;100;101;0;0;0]. And I want to use this. So I try to create a final logic which tracks this pattern and calculate the total stop time. I can do that since I know that every data point has the sample 1 [Hz]. Other knowledge is that it data starts and end with a stop.
My logic was, which didn´t work (it runs but gives back unexpected result, nothing useful), the following:
for i = 1:length(index)-1
for j = 2:length(index)
if index(i) > 0 && index(j) > 0
stop_start(i,1) = index(i);
elseif index(i) > 0 && index(j) == 0
stop_end(i,1) = index(i);
end
end
end
stop_time_tot = stop_start - stop_end;
Any ideas on what went wrong? I usually end up like this on ohter similar data sorting problems but never take it further but I want to get better and increase my knowledge...
All the best, Adam.
  댓글 수: 1
Asher
Asher 2019년 6월 2일
answering myself if anyone reading this!
It was not possible doing in this way, because the loop didn´t behave as expected, the for loops jumps, of course, one on one, not both together as my intention was... I forgot how for loops works basically! So they are not suited for this task! Instead I used the command >> "find", and some more lines to sort it out!
No probs!
//Adam

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by