Errorbar on bar graph using table values
이전 댓글 표시
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개)
Shubham Khatri
2020년 9월 3일
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
카테고리
도움말 센터 및 File Exchange에서 Errorbars에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!