MATLAB Legend title issue

1 回表示 (過去 30 日間)
Waqas Syed
Waqas Syed 2015 年 9 月 16 日
回答済み: Peter O 2015 年 9 月 18 日
Hi,
I an exectuing the following code to get a graph.
figure
grid
hold on;
for n=1:length(zeta_dom_r)
if abs(zeta_dom_r(n)-0.000)>0.0001
A(n)=0;
B(n)=0;
end
end
plot(A(:), B(:), 'k.-')
legend('Gain =0', 'Gain =0.05', 'Gain =0.1');
xlabel('\tau (s)');
ylabel('T Delay (s)');
xlim([0 5]);
ylim([0 0.5]);
I want to give one single title to legend i.e Gain. I do not want to write Gain again for every single line. Kindly let me know how to give title to the legend. I am using Matlab 2015.
  3 件のコメント
Walter Roberson
Walter Roberson 2015 年 9 月 17 日
You are only plotting one thing in this code, but you are supplying 3 legends. If this code is being invoked 3 times then the legend should be built afterwards.
In the code segment you show, should we assume that A and B have been set to values before this code?
It is recommended to switch to logical indexing.
idx = abs(zeta_dom_r) > 0.0001;
A(idx) = 0;
B(idx) = 0;
No loop.
Waqas Syed
Waqas Syed 2015 年 9 月 18 日
Thanks dpb. I will look into that.
And Thanks alot Walter. I knew that my programming technique was somehow inefficient.
And yes, A & B have been set to values before the code.

サインインしてコメントする。

回答 (1 件)

Peter O
Peter O 2015 年 9 月 18 日
You need to access the title string property of the legend:
There is likely a cleaner method to access this with the new graphics system, but here's how to do it in 2013b:
lh = legend('0','0.5','1');
set(get(lh,'Title'),'String','Gain');

カテゴリ

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