Preallocating of Structure without overwriting
2 次查看(过去 30 天)
显示 更早的评论
I have multiple Excel Files with the same structure but different values depending on the experiment. I load a bunch of those files into MatLab using
[numdata, textdata, ~] = xlsread(...)
Then I assign determine the number of files loaded and make a for loop to transfer the numerical data to the i-th index of my structure. This looks something like:
AutarkyData(i).ReactionTime = numdata(j)
Once I imported all my data and stored it appropiately, I calculate some values and also store them under AutarkyData (still in the for loop). Once all calculations are done, the result is exported to a new Excel File.
Everything is working so far, but the whole procedure gets increasingly slow once a multidude of files is imported. This is most probably due to the fact that I need to add new fields to the structure AutarkyData in the for loop, as it needs to add a new "column" to the structure with each new numdata it needs to import.
How do I preallocate my structure with the amount of files I selected without overwriting the existing values (maybe I want to add some values later)? I have an idea with how this would work with vectors/tables, but the syntax/buildup of a structure confuses me.
Thanks a lot in advance!
0 个评论
采纳的回答
Luna
2019-8-28
编辑:Luna
2019-8-28
I can recommend you to use datastore to process multiple files at once. This will be the faster than using xlsread. Actually it might be the fastest one.
You can read those links below:
A sample example:
ssds = spreadsheetDatastore('C:\Users\...\data');
data = ssds.readall;
It returns you a table containing to your data. Also you can specify includesubfolders or file extentions, etc.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!