function params = convertStructToCell(varargin)
% convert struct input to a cell array of name-value pairs to enable
% partial matching

%   Copyright 2021-2022 The MathWorks, Inc.

% If input is scalar, allow struct inputs as it may have been called
% internally with a struct input.  
if nargin == 1
    if ~(isstruct(varargin{1}) && isscalar(varargin{1}))
        error(message("stats:incremental:Learner:OnlyNVAllowed"));
    end
    fields = fieldnames(varargin{1});
    n = 2*numel(fields);
    params = reshape([fields.'; struct2cell(varargin{1}).'],[1,n]);
else % input must be a cell array of Name-Value pairs. 
    validInput = iscell(varargin) && mod(nargin,2)== 0;
    if ~validInput
        error(message("stats:incremental:Learner:OnlyNVAllowed"));
    end
    params = varargin;
end

end