Create plot with shaded standard deviation, but ...
244 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Vilém Frynta
el 13 de Mzo. de 2023
Comentada: Voss
el 14 de Mzo. de 2023
Hello,
I have tried searching on the internet about this issue, but I haven't found what I needed, so I'm here.
I am trying to create a plot that looks like this:
There are some important things that I need to say. The standard deviation will be different in each of the points. To be more specific, I will show you my data that I actually want to plot.
data = readmatrix("data.xlsx") % matrix with 3 columns
Each column contains numbers. From these numbers, an average value will and standard deviation will be calculated. Three columns, so only three values on the X axis.
Basic plot without these standard deviations would look like so:
% columns 2 and 3 are shorter, so i ignore NaN values
avg_data = [mean(data(:,1)), mean(data(~isnan(data(:,2)),2)), mean(data(~isnan(data(:,3)),3))]
std_data = [std(data(:,1)), std(data(~isnan(data(:,2)),2)), std(data(~isnan(data(:,3)),3))]
plot(1:3, avg_data)
I have all the data, but I am not aware how to create pretty plot with shaded areas. Other Mathworks Answers were usually using only one std for all the X values, but I have different std value for every X value.
0 comentarios
Respuesta aceptada
Voss
el 13 de Mzo. de 2023
data = readmatrix("data.xlsx") % matrix with 3 columns
% columns 2 and 3 are shorter, so i ignore NaN values
avg_data = mean(data,1,'omitnan')
std_data = std(data,0,1,'omitnan')
x = 1:size(data,2);
fill([x, flip(x)], [avg_data+std_data, flip(avg_data-std_data)], [0.8 0.8 0.8])
hold on
plot(x, avg_data, 'k')
2 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!