- Compute Means and Standard Deviations.
bar with mean, std and significance star
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Samayochita
am 25 Apr. 2025
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:
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:
0 Kommentare
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!