MATLAB Answers

Bar plot error using text function

28 ビュー (過去 30 日間)
Adriano
Adriano 2017 年 5 月 18 日
Answered: 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!!!

  0 件のコメント

サインイン to comment.

採用された回答

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 件のコメント

サインイン to comment.

More Answers (0)

サインイン してこの質問に回答します。

タグ


Translated by