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

17 次查看(过去 30 天)
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 个评论
Mathieu NOE
Mathieu NOE 2023-5-30
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 2023-5-30
编辑:Dustin 2023-5-30
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.

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2023-5-30
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.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by