
function [myRawData, mydata] = xls2saisir(filename)
%xls2saisir - reads an excel file
%function [saisir] = xls2saisir(filename)
%
%Input arguments
%==============
%filename: (string) name of the text Excel file in .xls format
%
%Reads an Excel file which has been saved under the format .xls (97-2004)
%the excel file includes the identifers of rows and columns 
% 
%The Excel format is compulsorily the following (example):
% varname1 varname2 varname3
%obsname1 number11 number12 number13
%obsname2 number21 number22 number23
%obsname3 number31 number32 number33
%
%The decimal separator is the point (".") NOT THE COMMA (",")

filename=upper(filename);
if(isempty(findstr('.xls',filename)))
   filename=[filename '.xls'];
end
if(nargin==1)
    [~, ~, rawData] = xlsread(filename);
    rawData(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),rawData)) = {''};
    
    [~, ~, raw] = xlsread(filename);
    raw(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),raw)) = {''};
    
    % Replace non-numeric cells with NaN
    R = cellfun(@(x) ~isnumeric(x) && ~islogical(x),raw); % Find non-numeric cells
    raw(R) = {NaN}; % Replace non-numeric cells
    
    % Create output variable
    myRaw = reshape([raw{:}],size(raw));
    
    % Clear temporary variables
    clearvars raw R;
else
  msgbox('Une erreur est survenue sur le nom du fichier, vérifiez que sa synthaxe ne contient pas de caractères spéciaux');
   
end 
mydata.d = myRaw;


%% Recherche et élimination des colonnes comportant que des NaN
indexCol ={}; 
k=1
for i=1:size(mydata.d,2) 
    
    if sum(isnan(mydata.d(:,i))) == size(mydata.d,1) 
        indexCol{k} = i;
        k=k+1;
    end
end
indexCol = fliplr(indexCol); % inversion du vecteur pour le ranger dans l'ordre décroissant

for i=1:size(indexCol,2)
    mydata.d(:,indexCol{i})=[];
end

%% Recherche et élimination des lignes comportant que des NaN
indexLine ={}; 
k=1
for i=1:size(mydata.d,1) 
    
    if sum(isnan(mydata.d(i,:))) == size(mydata.d,2) 
        indexLine{k} = i;
        k=k+1;
    end
end
indexLine = fliplr(indexLine); % inversion du vecteur pour le ranger dans l'ordre décroissant

for i=1:size(indexLine,1)
    mydata.d(indexLine{i},:)=[];
end;

clear i indexLine indexCol k

[n,p]=size(rawData);

mydata.i = char(rawData(2:n,1));
mydata.v = char(rawData(1, 2:p));

myRawData = rawData;