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 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