-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboxplots.m
94 lines (90 loc) · 2.4 KB
/
boxplots.m
1
function boxplots(x,varargin)% boxplots(x,catnames,dataname,notch,sym,vert,whis)% Create a boxplot using the columns of x.% The optional character matrix catnames contains% categorical names for the data sets and it has% as many rows as there are boxplots.% The third argument is an optional character% string for the response variable name. Additional arguments% correspond to those provided for the standard boxplot function.% Use boxplot if you don't want to modify the labels.% In accordance with the API for boxplot, all arguments must% be supplied if more than three arguments are needed. For instance,% notch and sym must be specified if vert is to be used.% For example, four horizontal nochted boxplots with labels% are created with this code:% x = rand(20,4);% catnames = strvcat('first','second','third','fourth');% notch = 1;% sym = '+';% vert = 0;% boxplots(x,catnames,'random data',notch,sym,vert)%% Use boxprep if there are multiple data sets that need% to be merged first.% December 12, 2002. , November 12, 2003, H. Gollwitzer% November 24, 2003. Cleaned up switch statementsif not(exist('boxplot')) error('Statistics Toolbox not installed')endif nargin < 1 error('No data.')end% Set up defaultsnotch = 0; % no notchsym = '+';vert = 1; % vertical alignmentwhis = 1.5;% How many boxplots?[m,n] = size(x);if min(m,n) == 1 n=1;end% n is number of categoriesargcount = length(varargin);switch argcount case 0 catnames = ''; dataname = ''; case 1 catnames = varargin{1}; dataname = ''; otherwise [catnames,dataname] = deal(varargin{1:2});endswitch argcountcase 0:2 ;case 3 notch = varargin{3};case 4 [notch,sym] = deal(varargin{3:4});case 5 [notch,sym,vert] = deal(varargin{3:5});case 6 [notch,sym,vert,whis] = deal(varargin{3:6});otherwise warning('More arguments than expected.')end% *** The call ***boxplot(x,notch,sym,vert,whis); % Take care of any ornamentationif (size(catnames,1) == n) & ischar(catnames) z = cell(1,n); for k = 1:n z{k} = deblank(catnames(k,:)); % remove trailing blanks end if vert % The usual orientation xlabel(''); set(gca,'XTicklabel',z); % use catnames in place of numerical tick labels. if not(isempty(dataname)) ylabel(dataname); end; else % horizontal ylabel(''); set(gca,'YTicklabel',z); % use catnames in place of numerical tick labels. if not(isempty(dataname)) xlabel(dataname); end; endend