![1standard deviation on power vs. frequency graph - 2020 01 18.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/262356/1standard%20deviation%20on%20power%20vs.%20frequency%20graph%20-%202020%2001%2018.png)
standard deviation on power vs. frequency graph
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
nines
el 18 de En. de 2020
Respondida: Star Strider
el 18 de En. de 2020
Hello all!
I am trying to put a shaded standard deviation on a power vs. frequency graph.
I've tried:
%errorbar
plot(f, mean(allspectrums_cortex_young)); hold on;
errorbar(f, std(allspectrums_cortex_young)/sqrt(13)); hold on;
fill(f, std(allspectrums_cortex_young)/sqrt(13),[1 0 0],'LineStyle','none');
title('Young Power - Cortex')
ylim([0 2000])
xlim([0 .15])
xlabel('Frequency (in hertz)');
ylabel('Power (n=13)'
%fill
plot(f, mean(allspectrums_cortex_young)); hold on;
fill(f, std(allspectrums_cortex_young)/sqrt(13),[1 0 0],'LineStyle','none');
title('Young Power - Cortex')
ylim([0 2000])
xlim([0 .15])
xlabel('Frequency (in hertz)');
ylabel('Power (n=13)'
and I get this:
![Screen Shot 2020-01-18 at 11.11.36 AM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/262352/Screen%20Shot%202020-01-18%20at%2011.11.36%20AM.png)
when I am looking for something more like:
![Screen Shot 2020-01-18 at 11.13.30 AM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/262353/Screen%20Shot%202020-01-18%20at%2011.13.30%20AM.png)
does anyone have any ideas? thanks so so much!
0 comentarios
Respuesta aceptada
Star Strider
el 18 de En. de 2020
It would help to have your data, however I created some to illustrate the approach:
f = linspace(0, 0.5, 25); % Frequency Vector
allspectrums_cortex_young = 1E+3*rand(5, 25) + 1600*exp(-10*f); % Synthetic Spectrum
mn_allspectrums_cortex_young = mean(allspectrums_cortex_young);
sd_allspectrums_cortex_young = std(allspectrums_cortex_young);
figure
plot(f, mn_allspectrums_cortex_young)
hold on
patch([f fliplr(f)], [(mn_allspectrums_cortex_young+sd_allspectrums_cortex_young) fliplr(mn_allspectrums_cortex_young-sd_allspectrums_cortex_young)], 'r', 'FaceAlpha',0.5, 'EdgeColor','none')
hold off
The approach (using the patch function) is to create a closed curve that patch then fills. That is done here by adding and then subtracting the std from the mean, after plotting the mean.
Example —
![1standard deviation on power vs. frequency graph - 2020 01 18.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/262356/1standard%20deviation%20on%20power%20vs.%20frequency%20graph%20-%202020%2001%2018.png)
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Teaching Resources en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!