Issues creating error bar for bar figure
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi,
I'm trying to create error bars on my bar plot.
I get the error: "Input arguments must be numeric, datetime, duration, or categorical."
I'm not sure what I'm doing wrong. Even when I make err equal to two numbers it still doesn't work.
AMean = 656631
BMean = 1130
ASTD = 237027
BSTD = 209
AHeight = 10
BHeight = 11
Names = ["A"; "B" ] ;
Averages = [AMean; BMean] ;
StandDev = [ASTD ; BSTD] ;
SampSize = [AHeight; BHeight] ;
NewTable = table(Names, Averages, StandDev, SampSize) ;
x = NewTable.Names ;
y = NewTable.Averages ;
err = StandDev ./ sqrt(SampSize) ;
bar(x, y)
errorbar(x,y,err)
댓글 수: 0
채택된 답변
Matt J
2025년 9월 11일
편집: Matt J
2025년 9월 11일
Here's an MWE:
x = ["A"; "B" ] ;
y = [3,4] ;
err = [0.5,0.75] ;
bar(x, y); hold on
errorbar(categorical(x),y,err,'r', 'Linestyle','none');
axis padded
댓글 수: 4
Chuguang Pan
2025년 9월 11일
@Kristine. In order to remove a line connecting, you can use Linestyle = 'none' as shown in the code:
errorbar(categorical(x),y,err,'r', 'Linestyle','none');
추가 답변 (1개)
Chuguang Pan
2025년 9월 11일
The problem lies in the variable Names is string array, which is not supported by errorbar function. You can use categorical function to convert string array to categries.
AMean = 656631;
BMean = 1130;
ASTD = 237027;
BSTD = 209;
AHeight = 10;
BHeight = 11;
Names = ["A"; "B" ] ;
Averages = [AMean; BMean] ;
StandDev = [ASTD ; BSTD] ;
SampSize = [AHeight; BHeight] ;
NewTable = table(Names, Averages, StandDev, SampSize) ;
x = NewTable.Names ;
y = NewTable.Averages ;
err = StandDev ./ sqrt(SampSize) ;
bar(x, y)
hold on
errorbar(categorical(x),y,err)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!