Effacer les filtres
Effacer les filtres

Errorbar on bar graph using table values

5 vues (au cours des 30 derniers jours)
Katherine Regalado Rosales
How can I add an error bar using table values to my bar graph?
Relevant code:
clear
close all
format shortG
T=readtable('experiment1.xlsx');
T.subject=double(T.subject);
T.video=double(T.video);
T.estimates=double(T.estimates);
T.verbs=cellstr(T.verbs);
T(1:5,:)
[v,verbs] = findgroups(T.verbs);
[meanEstimates]=splitapply(@mean,T.estimates,v);
meanEstimates=round(meanEstimates,1);
table1=table(verbs,meanEstimates);
table1=renamevars(table1,"meanEstimates","Mean speed estimate");
table1=renamevars(table1,"verbs","Verb");
table1=sortrows(table1,"Mean speed estimate","descend");
figure
hold on
b1=bar(categorical(table1{1:5, 1}), table1{1:5, 2});
xlabel("Verb");
ylabel("Mean speed estimate");
title(["SPEED ESTIMATES FOR THE VERBS"; "USED IN EXPERIMENT 1"]);
errorbar(x,y,err) % im not sure what to write for the inputs
  1 commentaire
Katherine Regalado Rosales
so far whats worked is
errorbar(categorical(table1{1:5, 1}), table1{1:5, 2}),'.');
but I'm supposed to make the size the std of mean Estimates

Connectez-vous pour commenter.

Réponses (1)

Shubham Khatri
Shubham Khatri le 3 Sep 2020
To my understanding, currently the size of the error bar would be the value of the data in ‘Mean speed estimate ‘ column of the table. To make the size equal to the standard deviation of the values, you need to calculate the standard deviation. After calculating the standard deviation, you need to scale it to the size of the data you want to plot. Please have a look at the code section below
figure
hold on
b1=bar(categorical(table1{1:5, 1}), table1{1:5, 2})
temp=std(meanEstimates); % Defining a temperory variable 'temp' having value of standard deviation of the meanEstimates
err=ones(size(table1{1:5,2}))*temp; % Scaling the variable 'temp' to the size of data in table (here 5x1)
errorbar(table1{1:5,2},err) % Plotting the error bars
xlabel("Verb");
ylabel("Mean speed estimate");
title(["SPEED ESTIMATES FOR THE VERBS"; "USED IN EXPERIMENT 1"]);
hold off
For more information on errorbar, click the link below

Catégories

En savoir plus sur Errorbars dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by