Home > freetb4matlab > general > accumarray.m

accumarray

PURPOSE ^

%

SYNOPSIS ^

function A = accumarray (subs, val, sz, func, fillval, isspar)

DESCRIPTION ^

% -*- texinfo -*-
% @deftypefn {Function File} {} accumarray (@var{subs}, @var{vals}, @var{sz}, @var{func}, @var{fillval}, @var{issparse})
% @deftypefnx {Function File} {} accumarray (@var{csubs}, @var{vals}, @dots{})
%
% Create an array by accumulating the elements of a vector into the
% positions defined by their subscripts.  The subscripts are defined by
% the rows of the matrix @var{subs} and the values by @var{vals}.  Each row
% of @var{subs} corresponds to one of the values in @var{vals}.
%
% The size of the matrix will be determined by the subscripts themselves.
% However, if @var{sz} is defined it determines the matrix size.  The length
% of @var{sz} must correspond to the number of columns in @var{subs}.
%
% The default action of @code{accumarray} is to sum the elements with the
% same subscripts.  This behavior can be modified by defining the @var{func}
% function.  This should be a function or function handle that accepts a 
% column vector and returns a scalar.  The result of the function should not
% depend on the order of the subscripts.
%
% The elements of the returned array that have no subscripts associated with
% them are set to zero.  Defining @var{fillval} to some other value allows
% these values to be defined.
%
% By default @code{accumarray} returns a full matrix.  If @var{issparse} is
% logically true, then a sparse matrix is returned instead.
%
% An example of the use of @code{accumarray} is:
%
% @example
% @group
% accumarray ([1,1,1;2,1,2;2,3,2;2,1,2;2,3,2], 101:105)
% @result{} ans(:,:,1) = [101, 0, 0; 0, 0, 0]
%    ans(:,:,2) = [0, 0, 0; 206, 0, 208]
% @end group
% @end example
% @end deftypefn

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:
Generated on Fri 22-May-2009 15:13:00 by m2html © 2003