# i have 300 sheets in one worksheet in excel. i wan to import this to matlab. I want to create loop where it reads all sheets and plot graph on a same graph.

1 view (last 30 days)
Shrutidat on 10 Apr 2022
Commented: Shrutidat on 20 May 2022
Patients = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\medicaldatasheet.xlsx','150','A7:A26'); %% X-axis constant for all plots
C1 = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\medicaldatasheet.xlsx', '150', 'D53:D72'); %% Cancer patients data Y axis of run number 150 (150 sheet name)
H1 = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\medicaldatasheet.xlsx', '150', 'E53:E72'); %%heart prob data y axis of run no 150 (150 sheet name)
L1 = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\medicaldatasheet.xlsx', '150', 'G7:G26'); %% Liver prob values
B1 = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\medicaldatasheet.xlsx' , '150', 'H7:H26); %% Bones values
K1 = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\medicaldatasheet.xlsx', '150' 'I7:I26'); %% Kidney values ..same for next sheet 151asfollows
C2 = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\medicaldatasheet.xlsx', '151', D53:D72'); next sheet in same workbook (151)
H2 = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\medicaldatasheet.xlsx', '151', E53:E72'); 151 Sheet no
L2 = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\medicaldatasheet.xlsx', '151', 'G7:G26');
B2 = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\medicaldatasheet.xlsx', '151', 'H7:H26');
K2 = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\medicaldatasheet.xlsx', '151', 'I7:I26'); same range goes for all the sheets in workbook.
plot(patients,C1)
hold on
plot(patients,C2)
hold off
plot(patients,H1)medicaldatasheet
hold on
plot(patients,H2)
plot(patients,B1)
hold on
plot(patients,B2)
hold off
plot(patients,L1)
hold on
plot(patients,L2)
hold off
plot(patients,K1)
hold on
plot(patients,K2)
hold off
I need all this 5 plots patients Vs C, CD vs patients Vs H, patients Vs B ,patients Vs L, patients Vs K just by mentioning the sheet numbers. for eg as mentioned above 150,151 sheets i want both the values of patients Vs C to be plotted in same graph so used hold on.
Shrutidat on 24 Apr 2022
Yes sir now this editing is fine for me. can u pls do the same for the provided answer?

VBBV on 10 Apr 2022
Edited: Jan on 20 May 2022
hold all
for I = 1:length(num)
B(:,I) = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\asd.xlsx', num2str(I), 'D53:D72');
C(:,I) = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\asd.xlsx', num2str(I), 'E53:E72');
E(:,I) = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\asd.xlsx', num2str(I), 'H7:H26');
F(:,I) = xlsread('C:\Users\varun\OneDrive\Desktop\New folder\asd.xlsx', num2str(I), 'I7:I26');
figure(1)
plot(A(:,I),B(:,I)) % coefficient for all 300 sheets
figure(2)
plot(A(:,I),C(:,I)) % coefficient for all 300 sheets
figure(3)
plot(A(:,I),D(:,I)) %
figure(4)
plot(A(:,I),E(:,I))
figure(5)
plot(A(:,I),F(:,I))
end
Shrutidat on 20 May 2022
Sir thank u so much 😭😭 And I'm really sorry for all the trouble 🥺

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by