Save variable from multiple excel spreadsheets
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
GreenValleyB
am 30 Jun. 2022
Kommentiert: Karan Kannoujiya
am 2 Jul. 2022
The excel-file is divided in different worksheets containing the same type of information. Each worksheet contains results from samples and has five columns containing different results from an anaylsis and 100.000 rows representing the number of cycles. I want to work with this data and I wanto to have one variable for each result instead of ten for each sample. The columns are named "maxStrain", "minStrain", "aveStrain", "maxVoid" and "minVoid". I want to create variables with these names that have the specific data from each spreadsheet. The import-function only allows me to import one sheet at a time and save it to one variable.
Is there a loop in the live editor I can implement, so that it goes from worksheet 12 to 21 importing the information from "B2:B100001"?
Example:
-variable maxStrain saves the data from the column "B2:B100001" from the worksheets 12 to 21.
-variable minStrain saves the data from the column "C2:C100001" from the worksheets 12 to 21 and so on with the other variables.
Thank you in advance!
0 Kommentare
Akzeptierte Antwort
Karan Kannoujiya
am 1 Jul. 2022
Bearbeitet: Karan Kannoujiya
am 1 Jul. 2022
Hi,
You can use below code to save the data for diffrent sheet--->
%define other varibles also like this
maxStrain=[];
minStrain=[]
tempmaxStrain=[];
tempminStrain=[];
locationOfExcel="C:\Users\Karan\Downloads\Book1.xlsx"; %location of your excel sheet
[~,sheets,~] = xlsfinfo(locationOfExcel); %saving all sheet name in sheets variable
for i = 1:length(sheets) %run from 12 to 21 in your case
[~,data,~] = xlsread(locationOfExcel,sheets{i});
data(1,:)=[]; %removing the column header
tempmaxStrain=data(:,1); %for saving first column maxStrain
maxStrain=[maxStrain;tempmaxStrain]; %combining each sheet information for differnt column
tempminStrain=data(:,2);%for saving second column minStrain
minStrain=[ minStrain;tempminStrain]; %combining each sheet information for differnt column
end
you can do for others column variables( "aveStrain", "maxVoid" and "minVoid") also.
I hope it helps.
2 Kommentare
Karan Kannoujiya
am 2 Jul. 2022
You can go through this link to read the excel sheet using readtable function instead of using xlsread function. I,m not sure why it is not saving the data.Can you please send the code you has written and also the screenshot of your excelfile data of any sheet ?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!