Matlab code optimization/variable preallocation
조회 수: 10 (최근 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에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!