Adding Labels to PDE Graph
2 views (last 30 days)
Show older comments
Madeleine Megg
on 17 Oct 2020
Commented: Madeleine Megg
on 17 Oct 2020
I was wondering how to add a label to a graph of multiple PDEs.
I want to label each line of the graph differently.
The functions I have are as follows:
function [pl,ql,pr,qr] = heatbc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = ur;
qr = 0;
end
function u0 = heatic(x)
u0 = x.*(1-x);
end
function [c,f,s] = heatpde(x,t,u,dudx)
c = 1;
f = dudx;
s = 0;
end
With the main code being as such:
x = linspace(0,1,10);
t = [0 0.1 0.2 0.3];
m = 0;
sol = pdepe(m,@heatpde,@heatic,@heatbc,x,t)
u = sol(:,:,1);
plot(x,u);
hold on;
So far the graph looks as such:
I would just like to know how I would code a legend that labels the purple, orange, red and blue lines individually.
Thanks in advance!
0 Comments
Accepted Answer
Alan Stevens
on 17 Oct 2020
One way is to do the following with your plot command:
plot(x,sol);
lg1 = ['t = ',num2str(t(1))];
lg2 = ['t = ',num2str(t(2))];
lg3 = ['t = ',num2str(t(3))];
lg4 = ['t = ',num2str(t(4))];
legend(lg1,lg2,lg3,lg4)
More Answers (0)
See Also
Categories
Find more on Boundary Conditions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!