bar with mean, std and significance star

2 次查看(过去 30 天)
Hi! How can I represent a bar graph of mean values and standard deviations with the star of significance level of a t-test upon the bars? I tried with 'barweb' but it doesn't work on my matlab version and also it does not display any significance stars. Thank you in advance! Gianluca

回答(1 个)

Samayochita
Samayochita 2025-4-25
Hey Gianluca,
A bar graph can be created with error bars and significance stars in MATLAB using basic plotting functions like “bar”,errorbar”, and “text” for the stars.
Here is how it could be achieved:
  1. Compute Means and Standard Deviations.
means = [mean(data1), mean(data2)];
stds = [std(data1), std(data2)];
2. Plot bars for mean values. Adds error bars for standard deviations.
figure;
b = bar(means, 'FaceColor', [0.2 0.6 0.5]);
hold on;
errorbar(1:2, means, stds, '.k', 'LineWidth', 1.5);
3. Perform t-test to get p-values.
[h, p] = ttest2(data1, data2);
4. Add Significance Stars (*, **, ***, or 'n.s.') using text and plot” based on p-values.
if p < 0.001
stars = '***';
elseif p < 0.01
stars = '**';
elseif p < 0.05
stars = '*';
else
stars = 'n.s.';
end
% Add stars above the bars
maxY = max(means + stds) + 0.2;
text(1.5, maxY, stars, 'HorizontalAlignment', 'center', 'FontSize', 14);
For more information on the MATLAB functions used above, please refer to the following documentation links:

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by