Split and group data in Array
6 views (last 30 days)
Show older comments
Luke on 3 Jan 2019
Commented: Cris LaPierre on 4 Jan 2019
I have array of size 2200056*1 and it is plotted below.
I want to split the array based on different steps.
Goal: I want to find index in figure2 based on input signal array (figure1).
In this case, from input of multiple steps(figure 1), the output should be index numbers 1,2,3,4,7,9,10,11
If array consist only one step signal then i can find index easily by taking median(array). But if the array has multiple sequences then how can we achieve it? I think if i can split data in to groups then it would be possible but not sure how to split it?
Here's one way if you want the values to be rounded to represent what is in your input speed array.
% Round values to remove perturbations
p10 = floor(log10(speed));
% Set resolution
p10(p10<1)=1; % smallest increment is 10
p10(p10>3)=3; % largest increment is 1000
tmp = speed./10.^p10;
newSpeed = round(tmp).*10.^p10;
% find and remove transitions
idx = find(diff(newSpeed)>0);
idx([inf; diff(idx)]>5000) = ;
% remove tail
idx = find(diff(newSpeed)<0);
steps = unique(newSpeed)
steps = 8×1
More Answers (2)
Use findgroups and splitapply functions.
Here is a simple example provided in the documentation
% Load table containing info for 100 patients
% Specify groups by gender with findgroups.
G = findgroups(Gender);
% Split Height into groups specified by G.
% Calculate the mean height by gender.
ans = 2×1
This approach will need some modification if your data is not just the step values (e.g. if it also contains values corresponding to the transition between each step). What to do in that scenario will depend on the actual data.
Find more on Matrices and Arrays 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!