Data sorting and logical expressions

7 views (last 30 days)
Asher
Asher on 29 May 2019
Commented: Asher on 2 Jun 2019
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 Comment
Asher
Asher on 2 Jun 2019
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

Sign in to comment.

Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!