Plotting a legend inside of a function with multiple variable names

조회 수: 10 (최근 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 CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by