Save variable from multiple excel spreadsheets
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Karan Kannoujiya
2022-7-1
编辑:Karan Kannoujiya
2022-7-1
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 个评论
Karan Kannoujiya
2022-7-2
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 ?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!