change display name of a data

21 ビュー (過去 30 日間)
Brasco , D.
Brasco , D. 2014 年 6 月 9 日
回答済み: José-Luis 2014 年 6 月 9 日
I am new begginer in Matlab and i have a problem with naming the data on graphs.
Let say i have 5 variables to plot and call teh " A, B, C, D, E "
i plot them on a figure and name them using legend command
legend ('A','B','C','D','E')
i want to change the fourth variable name. Let say i want it to display as "Fourth Variable"
how can i do this ??
Thanks for helping

回答 (1 件)

José-Luis
José-Luis 2014 年 6 月 9 日
You could modify only the text, but that is bound to wreak havok on the display:
plot(rand(10,5));
l_str = {'A','B','C','D','E'};
lH = legend(l_str);
pos_to_change = 4;
allH = get(lH,'children');
set(allH(numel(allH) - ( (pos_to_change - 1) * 3 ) ),'String','yourText');
It would probably be easier to update the entire legend:
new_str = l_str;
new_str(4) = {'yourText'};
legend(new_str);

カテゴリ

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