Using a Loop to read and store information?
1 次查看(过去 30 天)
显示 更早的评论
I have data stored in 10 different excel documents. Each document has the same table-like format. My goal is to read the information I want to use from the excel data, load it into my script, and reorganize it into a new excel sheet. For this question, I want to know if there is a way that I can use a while or for loop to load my data, rather than type out load for each document.
Each excel document is titled in ascending order, such as 'a1', 'a2' ... 'a10'
0 个评论
采纳的回答
Walter Roberson
2021-1-14
Or potentially you could use a datastore()
2 个评论
Walter Roberson
2021-1-15
dinfo = dir('a*.xlsx');
filenames = {dinfo.name};
filenames = natsortfiles(filenames);
numfiles = length(filenames);
datacell = cell(numfiles,1);
for K = 1 : numfiles
datacell{K} = readmatrix(filenames{K});
end
Now you can examine datacell{1}, datacell{2} and so on.
This code does not assume that the matrices are all the same size.
In the special case that they are all the same size, then
data = cat(3, datacell{:});
would create a 3D matrix where the third dimension corresponds to different files.
更多回答(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!