Find locations of repeated values?
显示 更早的评论
So, I have this function that takes a set of data and finds if there are values that repeat for more than 300 seconds in that data set...\
function FindRepetition(TruckVariableName)
setpref('Internet','SMTP_Server','lamb.corning.com');
data1 = (TruckVariableName);
x = length(TruckVariableName);
data = reshape(data1, 1, x);
datarep = ~diff(data) & data(2:x) ~= 0; %binary data -- 1 means repeats, 0 means different, excludes repetitive zeros
%if the difference in the data at each point is zero, and if the data at
%that point isn't itself zero, return true. 2:x means difference array is equal to the length of the data array, matrix dimensions must be the same or &
%cannot be used
datarepstr = num2str(datarep); %convert to string
s = regexprep(datarepstr,' ',''); %remove spaces
[startindex,runs] = regexp(s,'1+','start','match'); %find all runs and the point where they start
l = cellfun('length',runs); %find the length of each run
y = l > 300;
if any(y) %if any run is longer than 5 minutes, display message
%sendmail('johnsonlj2@corning.com', '2011 KENWORTH ISX15','A data fault has been detected - Prolonged data repetition');
disp('--An error has occurred - Prolonged data repetition.');
disp('Errors occurred at');
end
end
I want to find WHERE those repeated values start in that set of data. I tried disp(find(y));, but that finds the locations of the data set y, which is not the original data set. Anyone know how I can find the locations of data1 where the data repeats for more than 300 seconds?
采纳的回答
更多回答(1 个)
Muthu Annamalai
2013-7-15
Guessing from reading the code, and the comments in the code itself, you are looking for the variable, startindex
[startindex,runs] = regexp(s,'1+','start','match'); %find all runs and the point where they start
So just add this to your return value from the function, and you should be all set.
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!