. DN(IN)]
%
%   C = MAT2CELL(X,R) breaks up an array X by returning a single column
%   cell array, containing the rows of X. R must sum to the number of rows
%   of X. The elements of R determine the size of each cell in C, subject
%   to the following formula for I = 1:LENGTH(R),
%
%       SIZE(C{I},1) == R(I)
%
%   C = MAT2CELL(X,...,[],...) will return an empty cell array whose empty
%   size matches the lengths of the vector arguments, D1 through DN. Note
%   that the length of an empty vector is zero.
%
%   MAT2CELL supports all array types.
%
%	Example:
%	   X = [1 2 3 4; 5 6 7 8; 9 10 11 12];
%	   C = mat2cell(X,[1 2],[1 3])
%	    
%	See also CELL2MAT, NUM2CELL

% Copyright 1984-2014 The MathWorks, Inc.

    narginchk(2,Inf);
    
    % Allow use of a single input vector argument by assuming the remaining ones
    %   Remaining vectors will be the size of the input array along the
    %   respective dimension.  Necessary for backwards compatibility.
    if nargin == 2
        dims = ndims(x);
        varargin{dims} = 0;
        for n=2:dims
            varargin{n} = size(x,n);
        end
    end
    
    cellsize = cellfun('length',varargin);
    
    % Verify that the number of input arguments meets syntax requirements.
    if length(varargin) ~= ndims(x)
        % Check if the last input vectors have value 1 that would not
        %   affect the output
        vLengthInit = length(varargin);
        singleFlag = 0;
        while (isequal(varargin{end},1)) && (length(varargin) > ndims(x))
            varargin = {varargin{1:end-1}};
            singleFlag = singleFlag+1;
        end
        
        % If trailing ones were found and removed, report this and continue
        if singleFlag
            warning(message('MATLAB:mat2cell:TrailingUnityVectorArgRemoved', ...
                 vLengthInit,ndims(x),singleFlag));
        end
        
        cellsize = cellfun('length',varargin);
        
        if length(varargin) ~= ndims(x)
            error(message('MATLAB:mat2cell:ArgumentCountMismatch', ...
                length(varargin),ndims(x)));
        end
    end
    
    % Verify that all dimension size arguments are vectors
    if ~isequal(cellsize,cellfun('prodofsize',varargin))
        error(message('MATLAB:mat2cell:NonVectorArgument', ...
            length(varargin)));
    end
    
    % Verify that the input vectors sum to the input matrix dimensions.
    vecsums = zeros(size(varargin));
    for n = 1:length(vecsums)
        vecsums(n) = sum(varargin{n}(:));
    end
    if ~isequal(vecsums,size(x))
        error(message('MATLAB:mat2cell:VectorSumMismatch', length(varargin),num2str(size(x))));
    end

    % If an input vector was found to be empty, return an empty cell array
    %   as described in the help. This is necessary for backward
    %   compatibility.
    if any(cellfun('isempty',varargin))
        c = cell(cellfun('length',varargin));
        return
    end

    
    % If matrix is 2-D, execute 2-D code for speed efficiency
    if ndims(x)==2
        rowSizes = varargin{1};
        colSi# Estimate a One-Class SVM model
trainRows <- c(1:30, 51:80, 101:130)
testRows = !(1:150 %in% trainRows)
trainIris <- iris[trainRows,]
testIris <- iris[testRows,]

svmModel <- rxOneClassSvm(
    formula = ~Sepal.Length + Sepal.Width + Petal.Length + Petal.Width,
    data = trainIris)

# Add additional non-iris data to the test data set
testIris$isIris <- 1
notIris <- data.frame(
    Sepal.Length = c(2.5, 2.6),
    Sepal.Width = c(.75, .9),
    Petal.Length = c(2.5, 2.5),
    Petal.Width = c(.8, .7),
    Species = c("not iris", "not iris"),
    isIris = 0)
testIris <- rbind(testIris, notIris)  

scoreDF <- rxPredict(svmModel, 
     data = testIris, extraVarsToWrite = "isIris")
               
# Look at the last few observations
tail(scoreDF)
# Look at average scores conditioned by 'isIris'
rxCube(Score ~ F(isIris), data = scoreDF)
