how to preallocate a table in matlab for for loop to read multiple excel sheet
조회 수: 2 (최근 30일)
이전 댓글 표시
Here I modified a code from here to read a multiple excel sheets from a file. However, I do not know how to preallocate the empy table created since my variable 'Data' keep changing size for every loop iteration?
filename ='2012hf.xlsx';
[~,SheetNames] = xlsfinfo(filename);
nSheets = length(SheetNames);
VarNames ={'Day15','Day16','Day18','Day19'};
Data=table();
for ii=1:nSheets
Name=SheetNames{ii};
VarName=VarNames{ii};
Data=[Data, readtable(filename,'Sheet', Name,'Range','F1:F97')];
Data.Properties.VariableNames{'cmufc_HF'} = VarName;
end
S.Data=Data
댓글 수: 0
답변 (1개)
Image Analyst
2020년 6월 12일
You can either not worry about it (it may not speed things up or down that much), or else you can allocate way more than you need and set the remaining unused rows to null to crop them off.
댓글 수: 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!