plot help
显示 更早的评论
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
2012-5-11
vars = {'name1', 'name2'};
legend(vars{:});
3 个评论
Image Analyst
2012-5-11
Oh, is that what he wanted? You could be right. I had thought he wanted to have legends assigned automatically based on the names of the variables he plotted (rather than telling it the names explicitly). (I don't know how to do this, and don't even know if it's even possible.)
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
2012-5-11
If "vars" is a cell string... why do you need the {:}, why not just legend(vars) ?
类别
在 帮助中心 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!