function saveLearnerForCoder(obj,filename)
%SAVELEARNERFORCODER Saves an input model into a file used for code
%   generation. The input model can be one of: classification model, 
%   regression model and nearest neighbor searcher.
%
%   SAVELEARNERFORCODER(MDL,FILENAME) saves an input model as a struct
%   in a MAT-file, FILENAME. FILENAME must be a character vector. The model
%   can be one of: classification model, regression model and nearest
%   neighbor searcher. This MAT-file can be passed to loadLearnerForCoder for code
%   generation. Use the MAT-file, FILENAME to load and reconstruct the input 
%   model at compile-time.
%
%   See also LOADLEARNERFORCODER

%   Copyright 2019-2022 The MathWorks, Inc.

narginchk(2,2);
try
    if (isa(obj,'classreg.learning.classif.CompactClassificationSVM') || isa(obj,'classreg.learning.regr.CompactRegressionSVM')) &&...
            strcmpi(obj.KernelParameters.Function, 'linear') && ~isempty(obj.Alpha)
        warning(message('stats:classreg:coderutils:save:KeepSupportVectorsForCodegen','saveLearnerForCoder'));
    end
    classreg.coderutils.save(obj,filename);
catch ME
    throwAsCaller(ME);
end


