フィルターのクリア

Plotting a legend inside of a function with multiple variable names

2 ビュー (過去 30 日間)
DKalale
DKalale 2016 年 3 月 9 日
コメント済み: DKalale 2016 年 3 月 9 日
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);

採用された回答

Stephen23
Stephen23 2016 年 3 月 9 日
var = {{'legstr','legstr2'},'Location','eastoutside'};
legend(var{:})

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by