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