bar with mean, std and significance star

2 ビュー (過去 30 日間)
Gianluca Sesso
Gianluca Sesso 2015 年 9 月 2 日
回答済み: Samayochita 2025 年 4 月 25 日
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 Center および File ExchangeConvert Image Type についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by