errorbar with mean and standard deviation

32 visualizaciones (últimos 30 días)
Alberto Acri
Alberto Acri el 20 de Mzo. de 2022
Comentada: Voss el 20 de Mzo. de 2022
Hello, everyone. I have two input data (mean and standard deviation). I would like to create a graph similar to this one:
I have not found a suitable code. I had thought of an "errorbar". Does anyone know how to draw this graph?

Respuesta aceptada

Voss
Voss el 20 de Mzo. de 2022
Editada: Voss el 20 de Mzo. de 2022
% First, I create a random matrix x, and calculate
% the mean (x_mu) and standard deviation (x_std) of
% each column
% *You have this already*
N = 10;
x = randn(100,N);
x_mu = mean(x,1);
x_std = std(x,0,1);
% Now make the plot:
figure();
% mean +/- std:
x_max = x_mu+x_std;
x_min = x_mu-x_std;
% XData and YData of the error bar lines:
xd = (1:N)+([-0.1; 0.1; 0; 0; -0.1; 0.1; NaN]);
yd = [x_max([1 1 1],:); x_min([1 1 1],:); NaN(1,N)];
% create the error bar lines:
line(xd(:),yd(:),'Color','k');
% create a line for marking the mean of each column of x:
line(1:N,x_mu, ...
'Marker','s', ...
'MarkerSize',12, ...
'LineStyle','none', ...
'Color','k', ...
'MarkerFaceColor','w');
% set the grid and xlim:
grid on
xlim([0 N+1]);
  4 comentarios
Alberto Acri
Alberto Acri el 20 de Mzo. de 2022
ok thanks a lot
Voss
Voss el 20 de Mzo. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Errorbars en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by