Home > data-analysis > manip > cont > cont_add.m

cont_add

PURPOSE ^

cont_add makes a new cont. variable by adding up several other ones

SYNOPSIS ^

function cont_added = cont_add(varargin)

DESCRIPTION ^

 cont_add makes a new cont. variable by adding up several other ones

 USAGE:
 cont_add(VAR1 [, VAR2, VAR3, ...])
   Computes the sum at each time step of all the variables, creating a new
   cont. variable with the timestamps from VAR1.

 The variables must all have the same number of rows.

 This function takes multiple cont variables and produces one cont
 variable.  To take one cont variable and compute the sum of all its
 values, use cont_sum.

 See also: CONT_SUM, CONT_DIVIDE

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cont_added = cont_add(varargin)
0002 % cont_add makes a new cont. variable by adding up several other ones
0003 %
0004 % USAGE:
0005 % cont_add(VAR1 [, VAR2, VAR3, ...])
0006 %   Computes the sum at each time step of all the variables, creating a new
0007 %   cont. variable with the timestamps from VAR1.
0008 %
0009 % The variables must all have the same number of rows.
0010 %
0011 % This function takes multiple cont variables and produces one cont
0012 % variable.  To take one cont variable and compute the sum of all its
0013 % values, use cont_sum.
0014 %
0015 % See also: CONT_SUM, CONT_DIVIDE
0016 %
0017 
0018 % re-form the input args into a single matrix
0019 all_together = horzcat(varargin{:});
0020 values = sum(all_together(:, 2:2:end), 2);
0021 
0022 cont_added = horzcat(all_together(:, 1), values);
0023

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005