Why can't I add title to plot in R2013a?

3 ビュー (過去 30 日間)
Mohammed
Mohammed 2016 年 10 月 12 日
コメント済み: Mohammed 2016 年 10 月 13 日
I haven't used MATLAB in a while but last time I tried, I didn't have any issues with plotting function. Now when I am plotting and adding a title to the legend, apparently as shown below, It won't show up! Any suggestions toward fixing this issue would be greatly appreciated?!
clear, clc, clf, cla reset, format shortg,
g_compress = CompressExtract('CompressExtract.csv',2,1000);
g_table = g_compress(:,[1,12]);
g_Bins = g_table(:,1);
g_RSCP = g_table(:,2);
plot(g_Bins,g_RSCP,'-','Color',[0.5, 0, 0], ...
'LineWidth',1,'LineSmoothing','on')
lgd = legend('Example','Location','S');
title(lgd,'My Legend Title')
axis([0 1000 -100 -40]), grid on
  2 件のコメント
Preethi
Preethi 2016 年 10 月 13 日
hi,
do you want to title the plot or legend?
Mohammed
Mohammed 2016 年 10 月 13 日
I want to title the legend please?! Just like shown below

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

採用された回答

Ganesh Hegade
Ganesh Hegade 2016 年 10 月 13 日
編集済み: Walter Roberson 2016 年 10 月 13 日
Hi,
Normally for title
title(str)
title(str,Name,Value)
title(ax,___)
but the value of
lgd = legend('Example','Location','S');
is not a string or axis details.
I think you should just use 'legend(your specifications)' to locate the legend details on the graph and then add the title name.
Thanks.
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 10 月 13 日
編集済み: Walter Roberson 2016 年 10 月 13 日
In R2014a and before, legend() returned an axes handle, and you were able to title() against that handle.
In R2014b and newer, it turns out that you can set a Title property:
lgd.Title.String = 'My Legend Title';
In R2014a and before, there is the question of whether the default position is within the portion being displayed, and similar concerns. The way legends were constructed in R2014a and before was not expecting a title to be added.
Mohammed
Mohammed 2016 年 10 月 13 日
Thanks to both of you for your explanation. Here is what I improved;
clear, clc, clf, cla reset, format shortg,
g_compress = CompressExtract('CompressExtract.csv',2,1000);
g_table = g_compress(:,[1,12]);
g_Bins = g_table(:,1);
g_RSCP = g_table(:,2);
plot(g_Bins,g_RSCP,'-','Color',[0.5, 0, 0], ...
'LineWidth',1,'LineSmoothing','on')
lgd = legend('Example','Location','S');
lgd_title = get(gca,'title');
set(lgd_title, 'string', 'LegendTitle','FontWeight', 'Bold')
title(lgd,'My Legend Title')
axis([0 1000 -100 -40])
Here is how it looks like, my question to you both, how do I turn the box on around the legend title?

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by