Info

此问题已关闭。 请重新打开它进行编辑或回答。

How can I color a graph?

1 次查看(过去 30 天)
Andres Bayona
Andres Bayona 2019-11-15
关闭: MATLAB Answer Bot 2021-8-20
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 个评论
Walter Roberson
Walter Roberson 2019-11-15
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 2019-11-15
Generally speaking, look at fill() to color areas of a graph.

回答(0 个)

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by