MATLAB: How to read a .xls file in the matlab

read file

% loadModelXls.m - LOADS THE MODEL STRUCTURE AND PARAMETERS INTO MATLAB FROM AN EXCEL FILE
%
function [] = loadModelXls(idR)
global R;
warning off
% idR is the identifier of the reactor when more than one is simulated.
% The reactor no. 1 used (idR=1) requires no number in the xls sheets names.
% The second and following reactors, require the sheets names in the excel followed,...
% ... by the idR number at the end to indicate to which reactor they refer. e.g. StateVar2
if idR==1,id ==1;else id ==0;end
% VARIABLES AND PARAMETERS NAMES AND VALUES ARE READ FROM THE EXCEL FILE.
[OperatParam, pOpNames] = xlsread(strcat('MyParameters.xls'), strcat('OperatParam', id));
[StateVar, StNames] = xlsread(strcat('MyParameters.xls'), strcat('StateVar', id));
[AlgebraicParam,pAlgNames]= xlsread(strcat('MyParameters.xls'), strcat('AlgebraicParam', id));
[KineticParam, pKtNames] = xlsread(strcat('MyParameters.xls'), strcat('KineticParam', id));
[StoichMatrix, RateNames]= xlsread(strcat('MyParameters.xls'), strcat('StoichMatrix', id));
[FeedProgram, FdNames] = xlsread(strcat('MyParameters.xls'), strcat('FeedProgram', id));
FdNames = FdNames(2:size(FdNames,2));
RateNames = RateNames(1,2:size(RateNames,2));
% MATLAB STRUCTURE TYPE VARIABLES ARE CREATED FOR GROUP OF VARIABLES AND PARAMETERS WITH ...
% ...THE NAMES AND VALUES GIVEN IN THE EXCEL FILE AND FOR EACH REACTOR CONSIDERED.
%
% NOTE HOW SOME VARIABLES ARE ALSO COPIED INTO VECTORS TO FACILITATE
% MATRIX AND VECTOR OPERATIONS LATER. THAT IS THE CASE OF StV, AlgStV, rV, etc.
aux = '';
% Structure with the OPERATIONAL PARAMETERS named "pOp".
for i=1:length(OperatParam),
% Building the string command for the structure, last without ', '.





if i<length(OperatParam),
aux = strcat(aux, char(39), pOpNames(i), char(39), ', ',num2str(OperatParam(i)),', ');
else
aux = strcat(aux, char(39), pOpNames(i), char(39), ', ',num2str(OperatParam(i)));
end
end
aux = char(aux);
eval(strcat('pOp = struct(', aux, ');'));
pOp.pOpNames = pOpNames;
aux = '';
% Structure with the STATE VARIABLES AND THEIR INITIAL VALUES named "St".
for i=1:length(StateVar),
% Building the string command for the structure, last without ', '.
if i<length(StateVar),
aux = strcat(aux, char(39), StNames(i), char(39), ', ',num2str(StateVar(i)),', ');
else
aux = strcat(aux, char(39), StNames(i), char(39), ', ',num2str(StateVar(i)));
end
end
aux = char(aux);
eval(strcat('St = struct(', aux, ');'));
St.Phase = StNames(:,4);
St.StNames = StNames;
StV = StateVar;
aux = '';
% Structure with the ALGEBRAIC PARAMETERS named "needed for calcualtion of the algebra.
for i=1:length(AlgebraicParam),
% Building the string command for the structure, last without ', '.
if i<length(AlgebraicParam),
aux = strcat(aux, char(39), pAlgNames(i), char(39), ', ',num2str(AlgebraicParam(i)),', ');
else
aux = strcat(aux, char(39), pAlgNames(i), char(39), ', ',num2str(AlgebraicParam(i)));
end
end
aux = char(aux);
eval(strcat('pAlg = struct(', aux, ');'));
pAlg.pAlgNames = pAlgNames;
aux = '';
% Structure with the KINETIC PARAMETERS.
for i=1:length(KineticParam),
% Building the string command for the structure, last without ', '.
if i<length(KineticParam),
aux = strcat(aux, char(39), pKtNames(i), char(39), ', ',num2str(KineticParam(i)),', ');
else
aux = strcat(aux, char(39), pKtNames(i), char(39), ', ',num2str(KineticParam(i)));
end
end
aux = char(aux);
eval(strcat('pKt = struct(', aux, ');'));
pKt.pKtNames = pKtNames;
% STOICHIOMETRY MATRIX.
stoM = StoichMatrix;
% Structure with the FEEDING PARAMETERS.
aux = '';
for i=1:length(FdNames),
% Building the string command for the structure, last without ', '.
if i<length(FdNames),
aux = strcat(aux, char(39), FdNames(i), char(39), ', FeedProgram(:,', num2str(i+1), '), ');
else
aux = strcat(aux, char(39), FdNames(i), char(39), ', FeedProgram(:,', num2str(i+1), ')');
end
end
aux = char(aux);
eval(strcat('pFd = struct(', aux, ');'));
pFd.Time = FeedProgram(:,1);
pFd.FdNames = FdNames;
% Structure with the EFFLUENT COMPOSITION IS ALSO CREATED.
aux = '';
for i=1:length(StateVar),
% Building the string command for the structure, last without ', '.
if i<length(StateVar),
aux = strcat(aux, char(39), StNames(i), char(39), ', ',num2str(StateVar(i)),', ');
else
aux = strcat(aux, char(39), StNames(i), char(39), ', ',num2str(StateVar(i)));
end
end
aux = char(aux);
eval(strcat('Eff = struct(', aux, ');'));
Eff.Phase = StNames(:,4);
Eff.EffNames = [{'Qgas'}; {'Q'}; StNames(:,1)];
Eff.Qgas = 0; Eff.Q = 0;
for i=1:length(Eff.EffNames),
Eff.EffNames(i) = strcat(Eff.EffNames(i),'_out');
end
% ALL THE STRUCTURES ARE EMBEDDED INTO THE GLOBAL STRUCTURE R.
R(idR).pOp=pOp;
R(idR).St=St;
R(idR).StV=StV;
R(idR).pAlg=pAlg;
R(idR).pKt=pKt;
R(idR).pFd=pFd;
R(idR).Eff=Eff;
R(idR).stoM=stoM;
% % Structure with the parameter values.
% prm.FeedProgram = FeedProgram;
% prm.OperatParam = OperatParam;
% prm.StateParam = StateParam;
% prm.AlgebraicParam = AlgebraicParam;
% prm.KineticParam = KineticParam;
% prm.StoichMatrix = StoichMatrix;

Best Answer

That code already does read in several worksheets with lines of code like
[OperatParam, pOpNames] = xlsread(strcat('MyParameters.xls'), strcat('OperatParam', id));
which is the same as
[OperatParam, pOpNames] = xlsread('MyParameters.xls', ['OperatParam', id]);
so, what is your question?