How to add Data Labels to Graph

143 views (last 30 days)
%% i have 1:4 because the data is larger but I am trying to plot the first 4 values
x = 1:4;
data = final1(1:4,1);
y = data';
c = num2str(y);
errlow = [CI(1:4,1)];
errhigh = [CI(1:4,2)];
scatter(x,data)
hold on
er = errorbar(x,data(:,1),errlow,errhigh);
er.Color = [0 0 0];
er.LineStyle = 'none';
xlim([0,5]);
text(x,y,num2str(c);
I want to add a text next to each scatter plot for each y value but when I try this it plots all 4 values on each point. How can I add text to each corresponding point?

Accepted Answer

Star Strider
Star Strider on 16 Sep 2022
I can’t run the code because of missing data.
Instead of using num2str, use the compose function:
text(x,y,compose('%.2f',c))
Use the most appropriate format specifier for whatever ‘c’ is.
If you don’t have compose, use undocumented sprintfc function with the same syntax.
.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!