Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

How can I color a graph?

1 view (last 30 days)
Andres Bayona
Andres Bayona on 15 Nov 2019
Closed: MATLAB Answer Bot on 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 Comments
Walter Roberson
Walter Roberson on 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 on 15 Nov 2019
Generally speaking, look at fill() to color areas of a graph.

Answers (0)

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!