Matlab code optimization/variable preallocation

1 visualización (últimos 30 días)
Laura
Laura el 14 de Oct. de 2015
Hi all! I have written this code to do some calculations on excel files. The code works well, but it takes ages because I have a lot of excel files to process. I don't know how to optimize it because I am quite new to matlab. For instance I have been trying to preallocate mat_tot_flow, but I don't know how to do it because not knowing the final size of the matrix in advance I can't use the simple technique zeros(...,...). Any idea?
for i=1:length(source_files)
sheet='patterns';
raw_data=xlsread(fullfile(folder_path,source_files(i).name),sheet);
raw_data(:,1)=[];
total_flow=sum(raw_data,2);
xlswrite(fullfile(dest_directory, source_files(i).name),total_flow);
end
source_dir='name source path';
output_dir='name output path';
input_files=dir(fullfile(source_dir,'*xls'));
mat_tot_flow=[];
for k=1:length(input_files)
data=xlsread(fullfile(source_dir,input_files(k).name),'A:A');
mat_tot_flow=[mat_tot_flow,data];
end

Respuestas (0)

Categorías

Más información sobre Performance and Memory en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by