How to split data points into new numeric matrixs based on peaks
10 views (last 30 days)
Show older comments
I am trying to analysis finish dimension data of a machined part and create a control chart. However, the data is impacted by tool wear and must be analysed using linear regression. To do this I have to split data points between tool changes which can be seen in the data (based on troughs and peaks). See image of scatter plot below.

Obviously it would be time consuming to split the data in excel manually for 4 data sets each with 8000 points. I am hoping to code a way to identify the change between tool changes and place that data segment into a new numeric matrix and test for regression. For example dimensions will climb from 11.955 to 12 at which will drop back down to 11.949 after a tool change.
I know of the
findpeak(data)
But not sure how to split the data and place it into a new matrix.
How can I achieve this in MATLAB?
2 Comments
Mark Saad
on 13 Jun 2018
Edited: Mark Saad
on 13 Jun 2018
If your goal is to make a separate matrix of data after every peak, you could try to first get the number of peaks:
[pks, locs] = findpeaks(data);
numpeaks = length(pks);
Then make an array for each peak:
start_point = 1;
for i = 1:numpeaks
end_point = locs(i);
for j = start_point:end_point
split_data = data(start_point:end_point, :);
end
start_point = end_point + 1;
end
start_point and end_point set the range of data that you want to collect, so initially, start_point begins at the first point and data is collected until the first peak, which is end point. Then in the second iteration, start_point is now the point after the first peak, and end_point is now at the second peak, and so on.
This makes a new array through each iteration, so you could just make a larger variable before the loops to store all of the split data arrays.
Answers (2)
Guillaume
on 13 Jun 2018
You may need to tweak the options of findpeaks for you data (and finding the minimums by inverting your data may be more reliable), but once you've got the location of the peaks it trivial to split your vector into subvectors stored in a cell array:
[~, locs] = findpeaks(data); %maybe findpeaks(-data), or maybe use options
splitdata = mat2cell(data, 1, diff([1, locs, numel(data)+1])); %assumes data is a row vector
5 Comments
Guillaume
on 15 Jun 2018
locs is a column vector. Hence you need to use semicolons for concatenation:
splitdata = mat2cell(LatheB_BPTO, 1, diff([1; locs; numel(LatheB_BPTO)+1]));
If data is also a column vector:
splitdata = mat2cell(LatheB_BPTO, diff([1; locs; numel(LatheB_BPTO)+1]), 1);
Walter Roberson
on 15 Jun 2018
blocks = mat2cell(data, 1, diff(find([true,diff(data)<0,true])));
0 Comments
See Also
Categories
Find more on Data Preparation Basics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!