Find a row of repeated values?
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
Jacqueline
il 8 Lug 2013
0 voti
7 Commenti
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
il 8 Lug 2013
Evan
il 8 Lug 2013
You're welcome!
Jacqueline
il 8 Lug 2013
Evan
il 8 Lug 2013
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
il 8 Lug 2013
Jacqueline
il 11 Lug 2013
Categorie
Scopri di più su Data Type Identification in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!