0

所以在一个循环中,我希望只有在加载该循环中的数据成功时才执行所有语句。否则我希望循环继续到下一次迭代。

       for l=1:.5:numfilesdata

     if H(x,y)= load( ['C:\Users\Abid\Documents\MATLAB\Data\NumberedQwQoRuns\Run' num2str(t) '\Zdata' num2str(l) '.txt']);


      %%%%%Converting Files
      for x=1:50;
          for y=1:50;
           if H(x,y)<=Lim;
              H(x,y)=0;
           else
              H(x,y)=1;
          end
          end

          A(t,l)=(sum(sum(H))); %Area

          R(t,l)=(4*A(t,l)/pi)^.5; %Radius
      end
      end

如您所见,我正在递增 0.5,如果负载在该增量上不起作用,我希望循环基本上跳过所有操作并转到下一步。

谢谢你,阿比德

4

3 回答 3

1

在加载和处理之前检查文件是否存在:

if exist(filename,'file')
    ...
end
于 2011-10-23T08:41:47.327 回答
1

我不太确定这条线:

if H(x,y)= load( [...]); %# This tries to load dat file at x,y position in `H`

x 和 y 在第一次循环迭代时似乎未知,然后回退到 50,50(后续循环的最后一个索引)。

你可以试试:

H = load( [...]); %# This tries to load dat file in `H`

if numel(H) ~= 0
  %# iterate over H
end
于 2011-10-23T09:31:36.277 回答
1

您可以使用 TRY/CATCH 块:

for i=1:10
    try
        H = load(sprintf('file%d.txt',i), '-ascii');

        %# process data here ...

    catch ME
        fprintf('%s: %s\n', ME.identifier, ME.message)
        continue

    end
end
于 2011-10-23T23:39:46.013 回答