Bar plot error using text function

2 ビュー (過去 30 日間)
Adriano
Adriano 2017 年 5 月 18 日
回答済み: Star Strider 2017 年 5 月 18 日
Hi,
A friend with (Matlab2017) gave me this code:
label = categorical({'IBS';'ZEN';'RE';'LRS';'SEASONAL';'AAA';'COMBOCOMM';'A30';'BALANCE'});
temp = [ibs_perf; zen_perf; re_perf; lrs_perf; sea_perf; aaa_perf; com_perf; a30_perf; bal_perf];
bar(label,diag(temp),0.5,'stacked')
title('Strategies Performance Attribution','FontSize', 16)
set(gcf, 'Position', get(0, 'Screensize'));
grid on
grid minor
ylim([ylim2-0.1 ylim1+0.1])
lim = get(gca,'ytick');
a=[cellstr(num2str(get(gca,'ytick')'))];
pct = char(ones(size(a,1),1)*'%');
new_yticks = [char(a),pct];
set(gca,'yticklabel',new_yticks)
for i = 1:size(temp,1)
if temp(i,1) >= 0
text(label(i,1),temp(i,1),strcat(num2str(temp(i,1),'%0.2f'),'%'),...
'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
else
text(label(i,1),temp(i,1),strcat(num2str(temp(i,1),'%0.2f'),'%'),...
'HorizontalAlignment','center',...
'VerticalAlignment','top')
end
end
In my Matlab 2016a I recive this error:
Error using text
First two or three arguments must be numeric doubles.
How Can I fix the problem?
Thanks!!!

採用された回答

Star Strider
Star Strider 2017 年 5 月 18 日
You probably need to just use the index ‘i’. I could not get the ‘label’ reference to work correctly in R2017a and plot the correct x-coordinate of the text object, but then I don’t have your data.
See if this works in your code:
text(i,temp(i,1), ... etc ...);

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by