在Matlab循环中每次迭代后长时间停顿

时间:2014-08-21 10:49:06

标签: matlab loops

我正在使用Matlab脚本加载一堆图像,进程并将它们存储起来(见下文)。脚本运行正常,但在主循环的每个步骤之间有很长的暂停(每个步骤大约一个小时)。您对如何使其顺利运行有任何建议吗?

clear;
number_projections = 40; 
number_images_per_projection = 1386; 
offset = 5;
OB=zeros([number_images_per_projection 512 512]);
IM=zeros([number_images_per_projection 512 512]);

m = 0;
for j = 14:number_projections
    for k = 1:number_images_per_projection
      % Lets load the OB images
      t = sprintf('/data/alcer/Data_analysis/BL18_May2014/19_Nickel/Simulated_OB/OB_%03i_%05i.fits',j-1, k-1);
      m = m + 1;
      OB(m,:,:) = fitsread(t);
      % And now the corrected images
      u = sprintf('/data/alcer/Beamtimes/Data_BL18_May2014/MCP_detector/19_Nickel_1/Corrected/Ni_corrected_all/Nickel_1_%03i_%05i.fits',j-1, k-1);
      IM(m,:,:) = fitsread(u);
    end
    %Let's use a rolling median (5 images before and 5 after)

    rolling_median_IM = zeros([512 512]);
    rolling_median_OB = zeros([512 512]);
    clean_images = zeros([512 512]);

    for k = offset+1:number_images_per_projection-offset
        rolling_interval_IM = squeeze(IM(k-offset:1:k+offset,:,:));        
        rolling_interval_OB = squeeze(OB(k-offset:1:k+offset,:,:));
        rolling_median_IM(:,:) = squeeze(median(rolling_interval_IM,1));
        rolling_median_OB(:,:) = squeeze(median(rolling_interval_OB,1));
        clean_images(:,:) = ((squeeze(OB(k,:,:)))./squeeze(rolling_median_OB(:,:)))-((squeeze(IM(k,:,:)))./squeeze(rolling_median_IM(:,:)));
        v = sprintf('/data/alcer/Data_analysis/BL18_May2014/19_Nickel/Cleaned_images/Cleaned_Ni_%03i_%05i.fits',j-1, k-1);
        fitswrite(clean_images, v);
    end
end

1 个答案:

答案 0 :(得分:3)

尝试使用profile工具找出导致延迟的代码位。