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!