%% function [X, y, features, labels] = read_datamatrix(csvfile, target)
%  Function reads in csvfile treating target as the target variable, 
%  and reading the remaining numeric variables as features. 
%  Unique value of target variables are replaced with values of 1, 2, 3, etc. 
%  Feature names and target labels corresponding to 1, 2, 3 etc. are
%  returned

function [X, y, features, labels] = read_datamatrix(csvfile, target)

    dm = readtable (csvfile);
    varnames = dm.Properties.VariableNames;

    features = varnames (~strcmp(varnames, target));

    X = dm{:, features};
    y = dm{:, target};
    missing_target = ismissing(y);
    X(missing_target,:)=[];
    y(missing_target) = [];

    [labels, ~, y] = unique(y);
end