Borrar filtros
Borrar filtros

Errorbar on bar graph using table values

4 visualizaciones (últimos 30 días)
Katherine Regalado Rosales
Katherine Regalado Rosales el 1 de Sept. de 2020
Respondida: Shubham Khatri el 3 de Sept. de 2020
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 comentario
Katherine Regalado Rosales
Katherine Regalado Rosales el 1 de Sept. de 2020
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

Iniciar sesión para comentar.

Respuestas (1)

Shubham Khatri
Shubham Khatri el 3 de Sept. de 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

Categorías

Más información sobre Errorbars en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by