How to let Matlab divide my data on time interval [0 400] into multiple time intervals in one plot [0 30] [30 60] etc.

13 Ansichten (letzte 30 Tage)
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
  2 Kommentare
Mathieu NOE
Mathieu NOE am 30 Mai 2023
if you could do it for an interval of 400s , what is the issue for intervals of 50 seconds ?
make a for loop and shift the start / stop index of your data by 50 samples at each iteration
Dustin
Dustin am 30 Mai 2023
Bearbeitet: Dustin am 30 Mai 2023
I am a beginner and I did not write the code myself. I have to change it for my schoolproject.
I know some basics, but I don't know how to make this: make a for loop and shift the start / stop index of your data by 50 samples at each iteration. Can you help me write that code?
I have two vectors: time 1x1978
value 1x1978
Each 50 seconds has 259 datapoints.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 30 Mai 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;
figure
plot(t, s)
grid
xlabel('Time')
ylabel('Amplitude')
bufsz = Fs*50;
tbuf = buffer(t, bufsz);
sbuf = buffer(s, bufsz);
figure
hold on
for k = 1:size(sbuf,2)
sbuf(sbuf(:,end)==0,end) = NaN;
plot(tbuf(:,k), sbuf(:,k))
end
hold off
xlabel('Time')
ylabel('Amplitude')
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.
.

Weitere Antworten (0)

Produkte


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by