MATLAB Answers

0

How can i make xlsread read successive excel worksheets ?

Asked by Vasishta Bhargava on 30 Jun 2018
Latest activity Answered by Image Analyst
on 30 Jun 2018
I have a problem reading data from successive excel worksheets within a loop... The size of data in successive sheets are different, when I type the size of stored matrix ... it always shows the size of data in first worksheet ... why ?

  2 Comments

Post your code, such that we can know, what you are actually doing. What does "when I type the size of stored matrix" mean exactly?
[~,All]=xlsfinfo('C:\Users\bhargava\Desktop\Student data\III Year MID EXAM consolidated even sem 2016-17.xlsx');
for k=1:numel(All)
Sheets{k}=xlsread('III Year MID EXAM consolidated even sem 2016-17.xlsx',All{k});
end
[sss ddd] = xlsread('III Year MID EXAM consolidated even sem 2016-17.xlsx',All{17});
ALFe = []; ALFo = []; kk = 1;
pp = 1; while pp <= sss(:,1)
[dataPe dataNe Rawe] = xlsread('III Year MID EXAM consolidated even sem 2016-17.xlsx',All{pp});
[ss dd] = xlsread('III Year MID EXAM consolidated even sem 2016-17.xlsx',All{7});
TTe = dataPe(:,9:6:end);
[nxe nye]=size(TTe);
ne(pp) = nxe;
index = ss(1,9) % total
indT = ss(1,5) % theory
indL = ss(1,7) % lab
Le = TTe(:,indT+1:end)
Te = TTe(:,1:indT);
for i = 1:nxe % row %%passed in all subjects
for k = 1:indT
if Te(i,k) > 0.5*40
APSe(i,k) = 1;
else
APSe(i,k) = 0;
end
end
end
for i = 1:nxe % row
for k = 1:indL
if Le(i,k) > 0.4*100
VLe(i,k) = 1;
else
VLe(i,k) = 0;
end
end
end
Totale = [APSe VLe];
for i = 1:ne(kk) % row %% passed in all subjects P1 = sum(Totale(i,:)); if P1 == index %% All pass APe(i) = 1; else APe(i) = 0; end end
for i = 1:ne(kk) % row %% passed in all subjects P2 = sum(Totale(i,:)); if P2 > 3 %% Atleast three subjects passed ATPe(i) = 1; else ATPe(i) = 0; end end
for i = 1:ne(kk) % row %% passed in all subjects P3 = sum(Totale(i,:)); if P3 == 0 %% All fail ALFe(i) = 1; else ALFe(i) = 0; end end
ASPe = sum(APe) ASTPe = sum(ATPe) ASLFe = sum(ALFe) RPe(pp) = ASPe; RTe(pp) = ASTPe; RLe(pp) = ASLFe;
pp = pp + 1;
end
Re = [ne;RPe; RTe; RLe] bar([1:sss(:,1)],Re'); grid on legend('Total','All Pass','Passed >3','All fail')

Sign in to comment.

1 Answer

Answer by Image Analyst
on 30 Jun 2018
 Accepted Answer

Use
fileName = 'myExample.xlsx'
[status,sheets,xlFormat] = xlsfinfo(fileName )
to get the sheet names, then use xlsread() to open them
for k = 1 : length(sheets)
data = xlsread(fileName, sheets{k});
% Now do something with data....
end

  0 Comments

Sign in to comment.