%偏差をプロットする

data = fix( rand(1,8) * 10 + 1 );     %1〜10までの数値からランダムに8個選ぶ
subplot(2,1,1); bar(data); title('データ');

%平均値を求める
xbar = 1/length(data) * sum(data)

%平均値でグラフの色を変える
graph = zeros(length(data),2);
for count = 1 : 1 : length(data)
    if(data(count) < xbar)
        graph(count,:) = [data(count) (xbar - data(count))];
    else
        graph(count,:) = [xbar (data(count) - xbar)];
    end
end
subplot(2,1,2); bar(graph,'stack'); title('偏差');