Search code examples
matlabfor-loopif-statementmatlab-load

How to use if statement when condition is a successful load of data? MatLab


So In a loop, I want all statements to be executed only if the load if data in that loop is successful. Else I want the loop to continue to the next iteration.

       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

As you can see I am incrementing by .5, and if the load doesn't work on that increment I want the loop to essentially skip all the operations and go to the next step.

Thank You, Abid


Solution

  • Check if the files exists before loading and processing:

    if exist(filename,'file')
        ...
    end