Home > wafo > wstats > comnsize.m

# comnsize

## PURPOSE Check if all input arguments are either scalar or of common size.

## SYNOPSIS [errorcode,varargout] = comnsize(varargin)

## DESCRIPTION ```  COMNSIZE Check if all input arguments are either scalar or of common size.

CALL:  [errorcode,y1,y2,...,yN] = comnsize(x1,x2,...,xN);

errorcode = 0 , if all xi are either scalar or of common size.
1 , if the non-scalar xi do not match in size.
y1,...,yN = Same as x1,...,xN, except that scalars are transformed to
a constant matrix with same size as the other inputs.
x1,...,xN = Input arguments.

COMNSIZE makes sure that the output arguments are of common size.
This is useful for implementing functions where arguments can either
be scalars or of common size.

NOTE:  If the errorcode is 1, then yi = xi.

Examples:
A = rand(4,5);B = 2;C = rand(4,5);
[ec,A1,B1,C1] = comnsize(A,B,C);
ec2 = comnsize(A,1:2);```

## CROSS-REFERENCE INFORMATION This function calls:
 error Display message and abort function.
This function is called by:
 cplot Cubic plot of responses dist2dcdf Joint 2D CDF computed as int F(X1 mdist2dcdf Joint 2D CDF due to Plackett mdist2dcinv Inverse of the conditional cdf of X2 given X1. mdist2dpdf Joint 2D PDF due to Plackett given as f{x1}*f{x2}*G(x1,x2;Psi). walpharnd Random matrices from a symmetric alpha-stable distribution wbetacdf Beta cumulative distribution function wbetainv Inverse of the Beta distribution function wbetapdf Beta probability density function wbetarnd Random matrices from a Beta distribution wbetastat Mean and variance for the Beta distribution. wchi2cdf Chi squared cumulative distribution function wchi2inv Inverse of the Chi squared distribution function wchi2pdf Chi squared probability density function wchi2rnd Random matrices from a Chi squared distribution. weib2dcdf Joint 2D Weibull cumulative distribution function weib2dcinv Inverse of the conditional 2D weibull cdf of X2 given X1. weib2dpdf 2D Weibull probability density function (pdf). weib2dstat Mean and variance for the 2D Weibull distribution wexpcdf Exponential cumulative distribution function wexpinv Inverse of the Exponential distribution function wexppdf Exponential probability density function wexprnd Random matrices from an Exponential distribution wfcdf Snedecor's F cumulative distribution function wfinv Inverse of the Snedecor's F distribution function wfpdf Snedecor's F probability density function wfrechcdf Frechet cumulative distribution function wfrechinv Inverse of the Frechet distribution function wfrechpdf Frechet probability density function wfrechstat Mean and variance for the Frechet distribution. wfrnd Random matrices from the Snedecor's F distribution wfstat Mean and variance for the Snedecor's F distribution. wgamcdf Gamma cumulative distribution function wgaminv Inverse of the Gamma distribution function wgampdf Gamma probability density function wgamrnd Random matrices from a Gamma distribution. wgamstat Mean and variance for the Gamma distribution. wgevcdf Generalized Extreme Value cumulative distribution function wgevinv Inverse of the Generalized Extreme Value distribution function wgevpdf Generalized Extreme Value probability density function wgevrnd Random matrices from a Generalized Extreme Value distribution wgevstat Mean and variance for the GEV distribution. wggamcdf Generalized Gamma cumulative distribution function wggaminv Inverse of the Generalized Gamma distribution function wggampdf Generalized Gamma probability density function wggamrnd Random matrices from a Generalized Gamma distribution. wggamstat Mean and variance for the Generalized Gamma distribution. wgpdcdf Generalized Pareto cumulative distribution function wgpdinv Inverse of the Generalized Pareto distribution function wgpdpdf Generalized Pareto probability density function wgpdrnd Random matrices from a Generalized Pareto Distribution wgpdstat Mean and variance for the Generalized Pareto distribution. wgumbcdf Gumbel cumulative distribution function. wgumbinv Inverse of the Gumbel distribution function. wgumbpdf Gumbel probability density function. wgumbrnd Random matrices from a Gumbel distribution. wgumbstat Mean and variance for the Gumbel distribution. winvgcdf Inverse Gaussian cumulative distribution function winvginv Inverse of the Inverse Gaussian distribution function winvgpdf Inverse Gaussian probability density function winvgrnd Random matrices from a Inverse Gaussian distribution. winvgstat Mean and variance for the Inverse Gaussian distribution. wlogncdf Lognormal cumulative distribution function wlogninv Inverse of the Lognormal distribution function wlognpdf Lognormal probability density function wlognrnd Random matrices from a Lognormal distribution. wlognstat Mean and variance for the Lognormal distribution. wnormcdf Normal cumulative distribution function wnorminv Inverse of the Normal distribution function wnormpdf Normal probability density function wnormrnd Random matrices from a Normal distribution. wraylcdf Rayleigh cumulative distribution function wraylinv Inverse of the Rayleigh distribution function wraylpdf Rayleigh probability density function wraylrnd Random matrices from a Rayleigh distribution wtcdf Student's T cumulative distribution function wtinv Inverse of the Student's T distribution function wtpdf Student's T probability density function wtraylcdf Truncated Rayleigh cumulative distribution function wtraylpdf Truncated Rayleigh probability density function wtrnd Random matrices from a Student's T distribution wtweibcdf Truncated Weibull cumulative distribution function wtweibpdf Truncated Weibull probability density function wweibcdf Weibull cumulative distribution function wweibinv Inverse of the Weibull distribution function wweibpdf Weibull probability density function wweibrnd Random matrices a the Weibull distribution. wweibstat Mean and variance for the Weibull distribution.

## SOURCE CODE ```001 function [errorcode,varargout] = comnsize(varargin)
002 % COMNSIZE Check if all input arguments are either scalar or of common size.
003 %
004 % CALL:  [errorcode,y1,y2,...,yN] = comnsize(x1,x2,...,xN);
005 %
006 %  errorcode = 0 , if all xi are either scalar or of common size.
007 %              1 , if the non-scalar xi do not match in size.
008 %  y1,...,yN = Same as x1,...,xN, except that scalars are transformed to
009 %              a constant matrix with same size as the other inputs.
010 %  x1,...,xN = Input arguments.
011 %
012 %  COMNSIZE makes sure that the output arguments are of common size.
013 %  This is useful for implementing functions where arguments can either
014 %  be scalars or of common size.
015 %
016 %  NOTE:  If the errorcode is 1, then yi = xi.
017 %
018 % Examples:
019 %   A = rand(4,5);B = 2;C = rand(4,5);
020 %   [ec,A1,B1,C1] = comnsize(A,B,C);
021 %   ec2 = comnsize(A,1:2);
022
023 % Tested on: matlab 5.3
024 % History:
025 % revised pab 23.10.2000
026 %  - New name comnsize
027 %  - the input arguments can have a any dimension.
028 %  - Updated documentation
029 %  - Vectorized the calculations a bit more.
030 % Based on common_size.m by
031 %  KH <Kurt.Hornik@ci.tuwien.ac.at> Created: 15 October 1994
032
033
034 Np   = nargin;
035 Nout = max(nargout-1,0);
036 if Nout>Np,
037   error('The number of output arguments is too large.')
038 end
039
040 Ns =2;
041 sz = zeros(Np,Ns);
042 for ix = 1:Np,
043   tmp = size (varargin{ix});
044   Nt=length(tmp);
045   if Nt>Ns,sz=[sz,ones(Np,Nt-Ns)];Ns=Nt; end % Add singleton dimensions
046   sz(ix,1:Nt)=tmp;
047 end
048
049 csiz     = max(sz,[],1);        % find common size
050
051 % Check that non-scalar arguments match in size
052 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
053 errorcode = (any (any ((sz ~= 1)') & any ((sz ~= csiz(ones(Np, 1),:))')));
054
055 if Nout==0,return;end
056
057 isscalar = (prod(sz,2)==1)'; % find  mask to scalars
058 isscalar2 = isscalar(1:Nout); % Mask to those in output
059 ind  = find(isscalar2);  % indices to scalar arguments
060 if (errorcode|all(isscalar)|isempty(ind)),
061   varargout(1:Nout) = varargin(1:Nout);
062 else
063   ind0 = find(~isscalar2); % indices to non-scalar arguments
064   if any(ind0),
065     varargout(ind0) = varargin(ind0);
066   end
067   % Make sure the scalar arguments are of size csiz
068   for ix = ind,
069     varargout{ix} = varargin{ix}(ones(csiz));
070   end
071 end
072 return
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087```

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group

Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003