% 2011-02-01 Michele Tavella N = 100; Nc = 4; Nk = 3; D = rand(Nc, Nk, N); bars = {}; bars.x = 1:1:Nc; bars.w = 0.18; bars.dx = [-0.25 0.00 0.25]; bars.colors = {[1.00 0.00 0.00], ... [0.00 1.00 0.00], ... [0.00 0.00 1.00]}; bars.classes = {'Class 1', ... 'Class 2', ... 'Class 3'}; bars.groups = {'Group 1', ... 'Group 2', ... 'Group 3'}; figure(1); clf; for ik = 1:Nk Dik = squeeze(D(:, ik, :)); Mik = mean(Dik, 2); Sik = std(Dik, [], 2); hold on; h = bar(bars.x + bars.dx(ik), Mik, 'FaceColor', bars.colors{ik}); set(h, 'BarWidth', bars.w); errorbar(bars.x + bars.dx(ik), Mik, Sik, ... '.k', ... 'MarkerSize', 1, ... 'HandleVisibility','off'); hold off; end h = legend(bars.classes, 'Location', 'NorthEast'); set(h, 'EdgeColor', 'white'); set(gca, 'XTick', [1:1:Nc]); set(gca, 'XTickLabel', bars.groups); grid on; box on; ylim([0, 1]);