Bar plot error using text function
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Star Strider
il 18 Mag 2017
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Annotations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!