%% Integrate Matrix with Nonuniform Spacing
% Integrate the rows of a matrix where the data has a nonuniform spacing.
%
% Create a vector of x-coordinates and a matrix of observations that take place at the irregular intervals. The rows of Y represent velocity data, taken at the times contained in X, for three different trials.

X = [1 2.5 7 10];
Y = [5.2   7.7   9.6   13.2;
     4.8   7.0  10.5   14.5;
     4.9   6.5  10.2   13.8];

%
% Use trapz to integrate each row independently and find the total distance traveled in each trial. Since the data is not evaluated at constant intervals, specify X to indicate the spacing between the data points. Specify dim = 2 since the data is in the rows of Y.

Q1 = trapz(X,Y,2)

% The result is a column vector of integration values, one for each row in Y.
% Copyright 2012 The MathWorks, Inc.