Plot in increments of 30 seconds

Hello,
I wrote this script below which plots data over a period of 120 seconds, and divded it into increments of 30 seconds. I'm curious how to simplify this so I don't have to do it manually each time? Can it be done both with and without a for loop?
Thank you!
time30=find(x==30);
hold on
plot(x(1:time30),signal(1:time30));
time60=find(x==60);
hold on
plot(x(time30:time60),signal(time30:time60));
time90=find(x==90);
hold on
plot(x(time60:time90),signal(time60:time90));
time120=find(x==120);
hold on
plot(x(time90:time120),signal(time90:time120));
Screen Shot 2019-02-07 at 1.14.46 PM.png

回答 (1 件)

Kevin Phung
Kevin Phung 2019 年 2 月 7 日
編集済み: Kevin Phung 2019 年 2 月 7 日

0 投票

if you want to plot every 30-second segment as its own line object:
segment = reshape(1:120,30,4);
for i = 1:size(segment,2)
plot(x(segment(:,i)),signal(segment(:,i)));
hold on;
end
Let me know if this is what you wanted

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

質問済み:

2019 年 2 月 7 日

コメント済み:

2019 年 2 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by