How can i plot sections of a horizontal line?

9 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 18 Jul 2023
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 Comments
nicolas braveheart
nicolas braveheart on 18 Jul 2023
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])

Sign in to comment.

More Answers (0)

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!