Plot vertical lines with time in x-axis?

1 次查看(过去 30 天)
Hi all,
I have plotted a signal with time in x-axis as follows:
lengthinms = datalength/fs*1000;
dt = lengthinms/datalength;
t=(0:datalength-1)*dt;
plot(t,data)
Thereafter, I have calculated the maximum of the signal in the certain time interval:
[amp, lat] = max(data(w_min:w_max));
I have tried to plot two vertical lines around the maximum value as:
line([lat-24, lat-24], [0, amp]);
line([lat+24, lat+24], [0, amp]);
If I put samples on x-axis, the lines are placed correctly in the figure. However, when I put time in x-axis, the lines are in incorrect places. Could someone please let me know how can I plot the lines in the correct places when time is put on x-axis.
Thanks, Maria

采纳的回答

dpb
dpb 2014-12-14
lat is the index into the data array of the maximum location. You're not converting it to the time
t_lat=lat*dt;
line([t_lat-24, t_lat-24], [0, amp]);
etc., ...

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by