Adding a Legend with Variables as inputs
10 次查看(过去 30 天)
显示 更早的评论
Im very new to MATLAB and Ive got a script which takes in an array determined by the user, does some calculations and then plots it on a graph with the x-axis being in the range chosen by the user. So, naturally the number of curves in my graph will be a variable so how do I get it to show what on the legend. This is what Ive got so far but it is not working. (lambda is a constant).
hold on
for r = (minr : incrr : maxr) %start the plotting
z = (r./lambda).*((r./lambda).^(r-1)).*(exp(-(x./r).^r)); %The equation
plot(x,z)
xlabel('x');
ylabel('f(x)');
title('GRAPH__1');
end
for i = minr : incrr : maxr
labelr = sprintf('r = %.2f',r);
end
for j = lambda
label_lambda = sprintf('lambda = %.2f',lambda);
end
legend(labelr,label_lambda);
hold off
1 个评论
采纳的回答
Adam Danz
2020-1-22
编辑:Adam Danz
2020-1-22
Try this.
hold on
for r = minr : incrr : maxr %start the plotting
z = (r./lambda).*((r./lambda).^(r-1)).*(exp(-(x./r).^r)); %The equation
plot(x,z,'DisplayName',sprintf('r = %.2f',r))
xlabel('x');
ylabel('f(x)');
title('GRAPH__1');
end
% I'm not sure what this section is about....
% for j = lambda
% label_lambda = sprintf('lambda = %.2f',lambda); end
% end
legend(); % no need for inputs if you're using DisplayName
hold off
7 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!