Effacer les filtres
Effacer les filtres

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 vues (au cours des 30 derniers jours)
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 commentaires
Mathieu NOE
Mathieu NOE le 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 le 30 Mai 2023
Modifié(e) : Dustin le 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.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 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.
.

Plus de réponses (0)

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by