The scenario is I need to load data, which is in the form of struct array, from several .mat files and combine them into one single array for later processing. Initially what I did was like:
raw_data = [];
for i=1:length(file_name_list)
raw_data = [raw_data importdata(file_name_list(i))];
end
Then MATLAB warns me that:
The variable 'raw_data' appears to change size on every loop iteration. Consider preallocating for speed.
If I understand correctly, when appending to the array, MATLAB would reallocate some space and copy all the original elements to the new place so it might take a lot of time. However the question is that I don't know in advance how many struct will be in the files and I don't know the size of each struct. Is there a way to speed up the process? It already takes 5 seconds to finish 2 files with 600 struct in total (which is very slow).
Thank you for your help!