textscan
itself is very fast so it may be eating CPU, but you're not likely to improve on it performance-wise. However, it looks like you're not performing any sort of pre-allocation for your cell arrays. This means that Matlab may be constantly reallocating memory. Use cell
to create an empty cell array of the desired size:
num_archivo = numel(archivo);
Datos = cell(1,num_archivo);
AllNodos = cell(1,num_archivo);
AllTemp = cell(1,num_archivo);
for i = 1:num_archivo
...
end
...
(Though Datos
should probably not be a cell at @Lazarus pointed out.) You should do the same sort of thing for the other loops with sets
, vectn
, etc.
One other thing that I'd be sure to do is call fclose(fid);
immediately after you're done reading files(i).name
so that you don't have a bunch of open file pointers. Also, there seems to be no reason for saving the file id fid
to a cell array as you don't use it outside of the loop. Even if you did, a regular vector (allocated with numel(archive)
elements) would be better.