Matlab code optimization/variable preallocation
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!