Show constant in a Legend

35 views (last 30 days)
nikola oljaca
nikola oljaca on 23 Mar 2021
Commented: DGM on 24 Mar 2021
Hello guys,
My Question is how i can show my constants like x=4 and z=5 in my Legend.

Accepted Answer

DGM
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
nikola oljaca
nikola oljaca on 24 Mar 2021
Thank you for the answer but i just want to show the constants in my legend but not the graph of my constants. So i just work with the sprintf ?
DGM
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!