How do I insert values into my bar plot (with 2 columns per x value)?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
If I have a vector A and matrix B and make a bar plot, how do I list the corresponding y values at the top of each bar? (I understand that you use the text() function but I cannot get it to work). An example of what I want to accomplish:
A = [1 2 3 4 5]; B = [4 7; 2 9; 3 7; 4 8; 1 3]; bar(A,B);
% how do I properly use text() or something else to insert the data values located in B??
0 Kommentare
Antworten (1)
Conrad
am 30 Jan. 2013
You can try something like this:
A = [1 2 3 4 5];
B = [4 7; 2 9; 3 7; 4 8; 1 3];
bar(A,B);
xOffsets = [-0.16 0.16];
yOffsets = [0.16 0.16];
for i = 1 : size(B,2)
text(A + xOffsets(i), B(:,i)' + yOffsets(i), num2str(B(:,i)));
end
Conrad
0 Kommentare
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!