MATLAB: How to create plots for special areas of an array

areafindchangeptsplotsseperateSignal Processing Toolbox

Dear people,
I have a plot like this:
I want to plot each of the four waves separately. Of course I could just divide the whole length by 4 but then there would still be the noise from between the big waves. I tried to create a new array where all values smaller than 0.03 are deleted. But then I also delete those values of the big waves as well. Does anybody has an idea how to solve this? Thank you very much:)

Best Answer

This is perfect for the findchangepts (link) function, introduced in R2016a.
The Code
D = load('005a_100Hz.mat');
Ch9 = D.Channel_9_Data;
tv = D.Channel_1_Data; % Time Vector
[lpt,rsd] = findchangepts(Ch9, 'Statistic','rms', 'MaxNumChanges',8);
for k1 = 1:2:numel(lpt)-1
sig_seg{(k1+1)/2,1} = Ch9(lpt(k1):lpt(k1+1)); % Signal Values At Each Segment
sig_seg{(k1+1)/2,2} = lpt(k1):lpt(k1+1); % Index Range
end
vl = bsxfun(@times, ones(numel(lpt), 2), [min(Ch9) max(Ch9)]); % Create Vertical Lines For ‘figure(1)’
figure(1)
plot(tv, Ch9)
hold on
plot([tv(lpt),tv(lpt)]', vl', '-r', 'LineWidth',1.5)
hold off
grid
figure(2)
for k1 = 1:size(sig_seg,1)
subplot(size(sig_seg,1), 1, k1)
plot(tv(sig_seg{k1,2}), sig_seg{k1,1})
xlabel('Time (s)')
grid
end
The Plots