Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How can I color a graph?

1 Ansicht (letzte 30 Tage)
Andres Bayona
Andres Bayona am 15 Nov. 2019
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hi everybody
I wrote this code:
function[]=mifuncionsedimentos()
P=0:1:3000;
%Sólido
if (P<1200)
ts=((889+17900)/((P+54)+20200/(P+54)^2));
else
ts=(831+0.06*P);
end
%Líquido
tl=(1262+0.09*P);
plot(ts,P)
title("Diagrama de fases")
xlabel("T(K)")
ylabel("P(MPa)")
hold on
plot (tl,P)
legend({'Fase Sólida','Fase Líquida'},'Location','southeast')
I need to color the 3 areas of the graph that are separated by the two functions (ts, tl). The left area is "solid", the middle area is "melt fraction" and the right area is "liquid". How can I do that?
Thank you so much!
  2 Kommentare
Walter Roberson
Walter Roberson am 15 Nov. 2019
P=0:1:3000;
%Sólido
if (P<1200)
ts=((889+17900)/((P+54)+20200/(P+54)^2));
else
ts=(831+0.06*P);
end
needs to change to
P=0:1:3000;
ts = zeros(size(P));
%Sólido
mask = P<1200;
ts(mask) = ((889+17900)./((P(mask)+54)+20200./(P(mask)+54).^2));
ts(~mask) = (831+0.06*P(~mask));
Walter Roberson
Walter Roberson am 15 Nov. 2019
Generally speaking, look at fill() to color areas of a graph.

Antworten (0)

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by