필터 지우기
필터 지우기

plot help

조회 수: 2 (최근 30일)
Edward
Edward 2012년 5월 11일
Hi, im trying to write a simple program to put a legend on the graph using variable names as strings for example i have
var1='name1';
var2='name2';
how do i get these onto a legend?
I don't want to use legend(var1,var2) as i intend to plot n variables with n different names.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 5월 11일
vars = {'name1', 'name2'};
legend(vars{:});
  댓글 수: 3
Walter Roberson
Walter Roberson 2012년 5월 11일
In a duplicate of this question, the claim was made that this does not allow different numbers of strings for each execution. That is not correct.
For example,
nv = ceil(10 * rand);
vars = cell(1,nv);
for K = 1 : nv
vars{K} = char('a' + floor(20*rand(1,5)));
end
legend(vars{:})
Dr. Seis
Dr. Seis 2012년 5월 11일
If "vars" is a cell string... why do you need the {:}, why not just legend(vars) ?

댓글을 달려면 로그인하십시오.

카테고리

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