How to let Matlab divide my data on time interval [0 400] into multiple time intervals in one plot [0 30] [30 60] etc.
6 views (last 30 days)
I have a code for Matlab to plot my data on time interval 0s to 400s. I now want Matlab to divide that time interval in pieces of 50s, but I want to initial plot to stay in tact.
So I still want to see this initial example plot, but with the outlier rejection lines for each time interval of 50 seconds. Hope my problem is clear.
Thanks in advance
Star Strider on 30 May 2023
If you have the Signal Processing Toolbox, use the buffer function and a loop —
Fs = 259/50;
Tlen = 380;
t = linspace(0, Tlen*Fs, Tlen*Fs+1)/Fs;
f = 0.2;
s = sin(2*pi*t*f)*15-5 + randn(size(t))/10;
bufsz = Fs*50;
tbuf = buffer(t, bufsz);
sbuf = buffer(s, bufsz);
for k = 1:size(sbuf,2)
sbuf(sbuf(:,end)==0,end) = NaN;
You can also use reshape, although buffer is easier.
The calculations are straightforward, so I will let you explore them to understand how it works.