필터 지우기
필터 지우기

Errorbar on bar graph using table values

조회 수: 5 (최근 30일)
Katherine Regalado Rosales
Katherine Regalado Rosales 2020년 9월 1일
답변: Shubham Khatri 2020년 9월 3일
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
Katherine Regalado Rosales
Katherine Regalado Rosales 2020년 9월 1일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Shubham Khatri
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

카테고리

Help CenterFile Exchange에서 Errorbars에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by