How can i plot sections of a horizontal line?

9 次查看(过去 30 天)
Hi everyone,
i want to recreate the third section of the graph down below. As an input i have multiple measurements over time. This you can see in the two top sections. If one of the measurements is over a limit value a event is detected and should be shown in the bottom section. For example the acceleration in green is 4, the event starts and when it drops below 4 the event stops. For time the acceleration is over the 4, a gray bar should be shown in the bottom section. Does anyone has an idea how i can do that?
Thank you in advance for you help.
Regards,
Nick

采纳的回答

Star Strider
Star Strider 2023-7-18
One approach —
t = linspace(0, 15, 150);
v = ones(size(t));
G{1} = (t >=3 & t<=4);
G{2} = (t>=14 & t<=15);
K{3} = (t>=7 & t<=12);
K{2} = (t >= 1 & t<= 6.5);
K{1} = (t >= 7.5 & t <=14.5);
figure
plot(t(G{1}), v(G{1})*3, 'Color',[1 1 1]*0.8, 'LineWidth',5)
hold on
plot(t(G{2}), v(G{2})*2, 'Color',[1 1 1]*0.8, 'LineWidth',5)
for k = 1:numel(K)
plot(t(K{k}), v(K{k})*k, 'k', 'LineWidth',5)
end
yline([1 2 3], ':k')
hold off
yticks(1:3)
yticklabels({'BM','VM','KF'})
ylim([0 4])
.
  2 个评论
nicolas braveheart
nicolas braveheart 2023-7-18
Thanks for the quick reply. It works with one little adjustment, because i use version R2020b:
t = linspace(0, 15, 150);
v = ones(size(t));
G{1} = (t >=3 & t<=4);
G{2} = (t>=14 & t<=15);
K{3} = (t>=7 & t<=12);
K{2} = (t >= 1 & t<= 6.5);
K{1} = (t >= 7.5 & t <=14.5);
figure
plot(t(G{1}), v(G{1})*3, 'Color',[1 1 1]*0.8, 'LineWidth',5)
hold on
plot(t(G{2}), v(G{2})*2, 'Color',[1 1 1]*0.8, 'LineWidth',5)
for k = 1:numel(K)
plot(t(K{k}), v(K{k})*k, 'k', 'LineWidth',5)
end
yline(1, ':k')
yline(2, ':k')
yline(3, ':k')
hold off
yticks(1:3)
yticklabels({'BM','VM','KF'})
ylim([0 4])

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by