How to show the plot with the highest value?

2 visualizaciones (últimos 30 días)
Randomdude123
Randomdude123 el 22 de Oct. de 2020
Comentada: Walter Roberson el 25 de Oct. de 2020
Hey! How am I supposed to only show the plot with the highest values for h. The graph should show the plot with abs(T1) first and then change to abs(T2) when they intersect and abs(T2) get higher than abs(T1). With the following code I get both plots in all values
plot(h,abs(T1),'b')
hold on
plot(h,abs(T2),'g')
Thanks!
  6 comentarios
Star Strider
Star Strider el 22 de Oct. de 2020
Rik — Thank you!
Walter Roberson
Walter Roberson el 25 de Oct. de 2020
(Mathworks says we have to remove names upon request. Legal reasons, I guess.)

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 22 de Oct. de 2020
One approach would be ‘logical indexing’:
h = linspace(0,25);
T1 = 20 - h;
T2 = 10 + h;
Lv = abs(T2) > abs(T1); % Logical Index Vector
figure
plot(h,abs(T1),'b', 'LineWidth',2)
hold on
plot(h,abs(T2),'g', 'LineWidth',2)
plot(h(~(Lv)),abs(T1(~Lv)), '--r', 'LineWidth',1.0)
plot(h(Lv),abs(T2(Lv)), '--r', 'LineWidth',1.0)
hold off
Experiment to get the result you want.

Más respuestas (1)

the cyclist
the cyclist el 22 de Oct. de 2020
plot(h,max(abs(T1),abs(T2)))

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by