Find a row of repeated values?
显示 更早的评论
Hi, first off I am very new to Matlab. I asked a similar question yesterday but I don't think I was specific enough so I'm going to try again...
I am analyzing data that comes from a truck, such as engine speed, vehicle speed, etc. The data is collected randomly throughout the day for about 3 hours (10,000 seconds). I am trying to write a script that will detect any repetition in the data that last for 60 seconds or more. Because if that happens, there is something wrong with the sensors in the truck.
For example, if for engine speed I had 10,000 points ranging from 0-2100, and for 60 seconds in a row the data was stuck on 1,000, how would I write a script to detect this and say there is an error?
I appreciate any help I can get! Thanks
采纳的回答
更多回答(1 个)
Jacqueline
2013-7-8
0 个投票
7 个评论
Since the data is a column vector rather than a row vector, regexp cannot operate on a character array created from it. Does the following change fix your problem?
[ids runs] = regexp(regexprep(num2str(~diff(data.')),' ',''),'1+','start','match');
The only change is the addition of the "transpose" (.') operator to turn your column vector into a row vector.
Jacqueline
2013-7-8
Evan
2013-7-8
You're welcome!
Jacqueline
2013-7-8
Evan
2013-7-8
So you're saying that, if at any point the truck's velocity is zero, you wont want to consider that datapoint for your repetition check? If so, you can just add another condition to the creation of your logical vector:
datarep = ~diff(data) & data(2:end) ~= 0;
All this modification does is say "if the difference in the data at each point is zero, and if the data at that point isn't itself zero, return true."
The reason that I index from the second datapoint to the end is because your difference array will be one element shorter than your data array.
Jacqueline
2013-7-8
Jacqueline
2013-7-11
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Identification 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!