Can you exclude dates in date range using xlim?

I have a dataset where the x axis is time and the y axis is sound pressure level in dB. The data is recorded continuously on a 24hr cycle, but I'm not interested in the data collected at night. Is there a way to exclude this data using xticks or xlim?
At the moment I have:
xlim([start_dt, end_dt]); %filter to date range of interest
Would the best way to address this be to replace sd with multiple datetime ranges somehow to exclude the evening data? I'm not sure how to code this?

4 件のコメント

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 10 月 21 日
With xticks() and xticklabels(), you can show any values you'd need to display.
Louise Wilson
Louise Wilson 2021 年 10 月 21 日
Could you give an example of how it would be coded in terms of the date range?
KSSV
KSSV 2021 年 10 月 21 日
While plotting itself, you take the required data and plot.
Louise Wilson
Louise Wilson 2021 年 10 月 21 日
That is really not helpful, haha.

サインインしてコメントする。

 採用された回答

Chunru
Chunru 2021 年 10 月 21 日
編集済み: Chunru 2021 年 10 月 21 日

0 投票

dn = now + [0:.5:48]/24;
y = randn(size(dn));
subplot(311)
plot(dn, y)
datetick('x')
subplot(312)
idx = hour(dn)>7 & hour(dn)<20; % day
dn1=dn(idx);
y1=y(idx);
plot(dn1, y1)
datetick('x')
subplot(313)
idx = hour(dn)>7 & hour(dn)<20; % day
dn1=dn(idx);
y1=y(idx);
plot(1:length(y1), y1)
hold on
i1 = find(diff(dn1)>0.6/24);
xline(i1+1);
h=gca;
h.XTick=1:5:length(y1);
h.XTickLabel = datestr(dn1(1:5:end), 'HH:MM:SS');
h.XTickLabelRotation = 30;

3 件のコメント

Louise Wilson
Louise Wilson 2021 年 10 月 21 日
Thank you!
Louise Wilson
Louise Wilson 2021 年 10 月 21 日
After
xline(i1+1);
I get the error:
Error using xline (line 29)
Passing multiple values to ConstantLine is not supported.
Any ideas?
Chunru
Chunru 2021 年 10 月 22 日
What is your matlab ver? A work around is:
hold on
i1 = [4.1 5.3];
for i=1:length(i1)
xline(i1(i)+1);
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

リリース

R2020a

質問済み:

2021 年 10 月 21 日

コメント済み:

2021 年 10 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by