How to color an area at plot surface...
Mostra commenti meno recenti
How can i color the area between 2 functions like
f(x)=x^2
g(x)=-x^2+1
Risposta accettata
Più risposte (3)
Thomas
il 17 Apr 2013
You could use sth like
area(g);
hold on;
area(f);
and then select f's fill color to be the backgroud color.
Of coures this only works as long as f<g for all x.
If this is not the case you could first do
upperCurve = max(f,g)
lowerCurve = min(f,g)
and then plot upperCurve and lowerCurve as stated above. If they are sufficiently high-res compared to your plot resolution it might be sufficient, however it wouldn't be "clean". Maybe there is another solution anyone can bring up...
Masoud Ghanbari
il 18 Apr 2013
0 voti
Muruganandham Subramanian
il 18 Apr 2013
hi,
for e,g.
x=[1 2 3 4 5];
for i=1:numel(x)
f(i)=x(i)^2;
g(i)=-x(i)^2+1;
end
plot(x,f,x,g)
hold on;
area(f-g)
hold on;
area(g-f)
Do you expecting like this?
Categorie
Scopri di più su Surface and Mesh Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!