How can i plot sections of a horizontal line?

8 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 18 Lug 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 Commenti
nicolas braveheart
nicolas braveheart il 18 Lug 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])

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Labels and Annotations in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by