Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在MatLab中将误差条添加到分组条形图中_Matlab_Bar Chart_Errorbar - Fatal编程技术网

在MatLab中将误差条添加到分组条形图中

在MatLab中将误差条添加到分组条形图中,matlab,bar-chart,errorbar,Matlab,Bar Chart,Errorbar,我有一个简单的分组条形图。我也在试着画出误差条,但我似乎弄不明白 我不太擅长for循环,但我不知道这是否是唯一的解决方案,或者我是否可以添加另一行代码来绘制错误条 这是我的代码和图表: % Plot raw data y = [316.45 292.14 319.96; 305.59 287.99 295.21] % first 3 #s are pre-test, second 3 #s are post-test err = [13.12 5.67 12.36; 12.43 6.83 11

我有一个简单的分组条形图。我也在试着画出误差条,但我似乎弄不明白

我不太擅长for循环,但我不知道这是否是唯一的解决方案,或者我是否可以添加另一行代码来绘制错误条

这是我的代码和图表:

% Plot raw data
y = [316.45 292.14 319.96; 305.59 287.99 295.21]  % first 3 #s are pre-test, second 3 #s are post-test
err = [13.12 5.67 12.36; 12.43 6.83 11.67]

box on

bar(y)
set(gca,'xticklabel',{'Pre-test'; 'Post-test'}) 
ylim([200 360])
ylabel('RT (ms)')
xlabel('Session')

下面是一个使用标准errorbar和bar函数的解决方案。条形图在相同的x位置绘制每个组,并使用Xoffset特性移动组中的条形图。您可以使用x位置和Xoffset来绘制错误条

% Data
y = [316.45 292.14 319.96; 305.59 287.99 295.21]  % first 3 #s are pre-test, second 3 #s are post-test
err = [13.12 5.67 12.36; 12.43 6.83 11.67]

% Plot
figure(1); clf; 
hb = bar(y); % get the bar handles
hold on;
for k = 1:size(y,2)
    % get x positions per group
    xpos = hb(k).XData + hb(k).XOffset;
    % draw errorbar
    errorbar(xpos, y(:,k), err(:,k), 'LineStyle', 'none', ... 
        'Color', 'k', 'LineWidth', 1);
end

% Set Axis properties
set(gca,'xticklabel',{'Pre-test'; 'Post-test'});
ylim([200 360])
ylabel('RT (ms)')
xlabel('Session')

可能是Matlab的副本非常感谢!这是一个足够简单的循环,我能理解,我很感激