Code covered by the BSD License  

Highlights from
stdshade

4.0

4.0 | 1 rating Rate this file 23 Downloads (last 30 days) File Size: 1.53 KB File ID: #29534
image thumbnail

stdshade

by Simon Musall

 

25 Nov 2010 (Updated 01 Dec 2010)

Short code to create shading around a mean. Input is a matrix with rows of observations.

| Watch this File

File Information
Description

usage: stdshade(amatrix,alpha,acolor,F,smth)
plot mean and standard deviations(std) coming from a matrix of data, at which each row is an observation. std can be changed to standard error of the mean(sem) in the code. sem/std is shown as shading.

- acolor defines the used color (default is red)
- F assignes the used x axis (default is steps of 1).
- alpha defines transparency of the shading (default is no shading and black mean line)
- smth defines the smoothing factor (default is no smooth)

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
14 Jan 2011 Jeff Tuhtan

Useful file, but a few changes can be made, as it did not work at the onset:

if exist('F','var')==0 || isempty(F);
    F=1:size(amatrix,1);
end

The above code had returned the size of the columns.

and

amean=smooth(amatrix,smth)';

The above code had used nanmean, which calculated the mean of the whole dataset, resulting in only a point being plotted.

14 Jan 2011 Simon Musall

Thanks for your suggestions.

I'm not quit sure if I understand your changes though. When you change the size to the fir dimension, it gives you the amount of observations instead of their actual length. When I try to change it that way, the code breaks as F and the mean of observations has not the same length anymore.

Have you tried using amatrix' as an input instead? Maybe you are using a different matrix structure as I do.

24 May 2011 Thorsten Bartels-Rausch

Hi...thanks, works great, looks great!
except: On Mac (and Linux) the axes vanish once the shaded areas are introduced. (This seems to be connected with the OpenGL renderer that is used for alpha values below 1). A work around is to change the view-angle just a little by adding this line somewhere after stdshade is called:
camva(gca,camva+(camva/1000))

25 May 2011 Simon Musall

Hi Thorsten,

thanks for your suggestion. Apparently, the axis can also vanish under Win7. I think, the reason for this is the stretch-to-fill behavior (which is also disabled when changing the view-angle). I thought about adding this fix into the code but unfortunately it creates new problems e.g. when doing subplots. If someone has the axis problem, it therefore seems to make most sense to find a individual solution which produces a figure that fits the needs best. I found it useful to change the axis aspect ratio to disable stretch to fill:

http://www.mathworks.com/help/techdoc/visualize/f4-24991.html

Please login to add a comment or rating.
Updates
30 Nov 2010

Minor changes:
shorter name
mean line uses selected color
transparency can be excluded

01 Dec 2010

fixed known spelling errors

Tag Activity for this File
Tag Applied By Date/Time
errorbar Simon Musall 29 Nov 2010 08:55:33
shading Simon Musall 29 Nov 2010 08:55:33
sem Simon Musall 29 Nov 2010 08:55:34
standarderror Simon Musall 29 Nov 2010 08:55:34
shade Simon Musall 30 Nov 2010 13:35:41
mean Simon Musall 30 Nov 2010 13:35:41
shade Nhu Che 03 Jun 2011 00:52:10
shade Giuseppe 02 Dec 2011 17:05:43

Contact us at files@mathworks.com