How to add Data Labels to Graph

99 Ansichten (letzte 30 Tage)
Pushti Shah
Pushti Shah am 16 Sep. 2022
Beantwortet: Star Strider am 16 Sep. 2022
%% 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?

Akzeptierte Antwort

Star Strider
Star Strider am 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.
.

Weitere Antworten (0)

Kategorien

Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by