title: Is there a more elegant way to write these loops?
body: <p>I have a script that requires a handful of parameters to run.  I'm interested in exploring the results as the parameters change, so I define a few <code>scan</code> arrays at the top, wrap the whole code in multiple <code>for loops</code> and set the parameters values to the current scan values.  </p>
  
  <p>This is error prone and inelegant. The process for changing the code is: 1) reset <code>scan</code> variables at the top, 2) comment out eg <code>b = scan2(j2)</code> and 3) uncomment <code>b=b0</code>.  </p>
  
  <p><strong>What's a better method to allow variables to be set to arrays, and subsequently run the code for all such combinations?</strong>  Example of my code now:</p>
  
  <pre><code>close all
  clear all
  
  %scan1 = linspace(1,4,10);
  scan1 = 0;
  scan2 = linspace(0,1,10);
  scan3 = linspace(-1,0,10);
  
  for j3 = 1:length(scan3)
    for j2 = 1:length(scan2)
      for j1 = 1:length(scan1)
  
        a = a0;
        %b = scan2(j2);
        b = b0;
        %c = c0;
        c = scan3(j3);
        d = scan2(j2);
  
        %(CODE BLOCK THAT DEPENDS ON variables a,b,c,d...)
  
      end
  
    end
  
  end
  </code></pre>