Show constant in a Legend
35 views (last 30 days)
Show older comments
Hello guys,
My Question is how i can show my constants like x=4 and z=5 in my Legend.
0 Comments
Accepted Answer
DGM
on 24 Mar 2021
Edited: DGM
on 24 Mar 2021
You can use sprintf() to build the legend string from literal text and an assortment of variables. For example:
% dummy parameters
p=[1 2 3];
x=linspace(0,1,100);
for n=1:numel(p)
y=x.^p(n);
subplot(1,numel(p),n)
plot(x,y)
legend(sprintf('y=x^%d',p(n)),'location','northwest')
end
Yields us this plot:
2 Comments
DGM
on 24 Mar 2021
If all you need is the legend, just use that. The rest is just context for sake of the example.
More Answers (0)
See Also
Categories
Find more on Legend 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!