plot a vertical line on datetime axis of a time series
24 次查看(过去 30 天)
显示 更早的评论
Hi! I have 4 waveforms which i want to plot by using the subplot fonction. For each of them i want to plot a vertical line at a specific time. Here is my code to plot my waveform:
figure1=figure
for k4=1
File4=AllFiles4(k4).name;
X4=rdmseed(strcat(P4,File4)); %('AllFiles(k).name');
d9 = cat(1,X4.d);
% dd7=d7*gainfac2;
d10=d9/max(d9); %d2=d1/max(d1);
d6=bandpass(d10,[0.01 50],s_rate); %d3==bandpass(d2,[4 50],s_rate)%
ndp=length(d10); %ndp=length(d3);
t=[0:dt:(ndp-1)/s_rate];
dt2=datetime(2021,07,09,16,32,t);
% ndp2=length(d6);
subplot(4,1,1);
plot(dt2,d10) %plot(dt2,d4)
ylabel('Amplitude (counts)')
xlabel('time (hh:mn:ss)')
title('Waveform Geophone / Jul21')
% hold on
% tMark = datetime(16,32,41);
% % % plot([tMark tMark], 'color', 'r', 'LineWidth', 1);
% plot([tMark tMark], ylim, 'color', 'r', 'LineWidth', 1);
%
% hold off
end
when i uncomment the line that i wrote for the plot of this verical line, which are the following lines
hold on
tMark = datetime(16,32,41);
% % plot([tMark tMark], 'color', 'r', 'LineWidth', 1);
plot([tMark tMark], ylim, 'color', 'r', 'LineWidth', 1);
hold off
i got the this as plot:
can someone help me on this? i want to plot this red vertical line in each of the waveform (here was for the plot in subplot (4,1,1) at the time position 16:32:41.
0 个评论
回答(1 个)
Star Strider
2022-10-18
Perhaps —
dt = 1E-2; % Create Data
ndp = 1E+4; % Create Data
s_rate = 100; % Create Data
t=[0:dt:(ndp-1)/s_rate];
dt2=datetime(2021,07,09,16,32,t);
d10 = randn(size(dt2)) .* sin(2*pi*second(dt2)/10) % Create Data
% ndp2=length(d6);
subplot(4,1,1);
hold on
plot(dt2,d10) %plot(dt2,d4)
ylabel('Amplitude (counts)')
xlabel('time (hh:mn:ss)')
title('Waveform Geophone / Jul21')
tMark = datetime(2021,07,09,16,32,41);
plot([tMark tMark], ylim, 'color', 'r', 'LineWidth', 1);
hold off
You need to define the date as well as the time in ‘tMark’.
.
4 个评论
Star Strider
2023-3-22
Thank you!
At the top of the Answer window on the right there are a number of options: Vote, Link, etc. Clicking on Vote should work.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!