Plotting a legend inside of a function with multiple variable names
14 次查看(过去 30 天)
显示 更早的评论
I am having trouble figuring out this issue, basically I have a plot with several x,y sets plotted and I want to apply a legend to the plot.
Something like this does exactly what I want:
figure, plot(1:1:10,1:1:10,1:1:10,1:2:20)
legend({'legstr','legstr2'},'Location','eastoutside')
However, I want to do this:
figure, plot(1:1:10,1:1:10,1:1:10,1:2:20)
var = {{'legstr','legstr2'},'Location','eastoutside'};
legend(var)
Basically, I want to do this so that I can determine "var" programmatically and pass it into a function. What is the proper syntax to do this... I am betting it is something obvious.
The error I get is this:
Error using legend>process_inputs (line 517)
Cell array argument must be a cell array of strings.
Error in legend>make_legend (line 303)
[orient,location,position,children,listen,strings,propargs] =
process_inputs(ha,argin); %#ok
Error in legend (line 257)
[~,msg] = make_legend(ha,args(arg:end),version);
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!