title: matlab error, attempt to reference field of non structure array
body: <p>All the references to this error I could find searching online were completely inapplicable to my situation, they were dealing with some kind of variables involving dots, like <code>a.b</code> (structures in other words), whereas I am strictly using arrays. Nothing involves a dot, nor does my code ask about it.</p>
  
  <p>Ok, I have this GINORMOUS array called <code>tier2comparatorconnectionpoints</code>. It is a 4-D array of size 400×10×20×10. Consider <code>tier2comparatorconnectionpoints(counter,counter2,counter3,counter4)</code>.</p>
  
  <ul>
  <li><code>counter</code> is a number <code>1</code> to <code>400</code>,</li>
  <li><code>counter2</code> is a number <code>1</code> to <code>numchromosomes(counter)</code>, and <code>numchromosomes(counter1)</code> is bound to <code>10</code>,</li>
  <li><code>counter3</code> is a number <code>1</code> to <code>tier2numcomparators(counter,counter2)</code>, which is in turn bounded to <code>20</code>.</li>
  <li><code>counter4</code> is a number <code>1</code> to <code>tier2inputspercomparator(counter,counter2,counter3)</code>, which is bounded to <code>10</code>.</li>
  </ul>
  
  <p>Now, so that I don't run out of RAM, I have <code>tier2comparatorconnectionpoints</code> as type <code>int8</code>, and UNFORTUNATELY at some point in my horrendous amount of code, I forgot to cast it to a <code>double</code> when I'm doing math with it, and a rounding error involved with multiplying it with a <code>rand</code> ends up with <code>tier2comparatorconnectionpoints</code> for some values of its <code>4</code> inputs exceeding what it's allowed to be. </p>
  
  <p>The values it's allowed to have are 1 through <code>tier1numcomparators(counter,counter2)</code>, which is bounded to <code>40</code>, <code>41</code> through <code>40+tier2numcomparators(counter,counter2)</code>, with <code>tier2numcomparators(counter,counter2)</code> being bounded to <code>20</code>, and <code>61</code> through <code>60+tier2numcomparators(counter,counter2)</code>, thus it's not allowed to be more than <code>80</code> since <code>tier2numcomparators(counter,counter2)</code> is bounded to <code>20</code> and it's not allowed to be more than <code>60+tier2numcomparators(counter,counter2)</code>, but it's also not allowed to be less than <code>40</code> but more than <code>tier1numcomparators(counter,counter2)</code> and it's not allowed to be less than <code>60</code> but more than <code>40+tier2numcomparators(counter,counter2)</code>. I became aware of the problem because it was being set to <code>81</code> somewhere.</p>
  
  <p>This is an evolutionary simulation by the way, it's natural selection on simulated organisms. I need to hunt down the part of the code that is allowing the values of <code>tier2comparatorconnectionpoints</code> to exceed what it's allowed to be. But that is a separate problem.</p>
  
  <p>A temporary fix of my data, just so that it at least is made to conform to its allowed values, is to set anything that is greater than <code>tier1numcomparators(counter,counter2)</code> but less than <code>40</code> to <code>tier1numcomparators(counter,counter2)</code>, to set anything that is greater than <code>40+tier2numcomparators(counter,counter2)</code> but less than <code>60</code> to <code>40+tier2numcomparators(counter,counter2)</code>, and to set anything that is greater than <code>60+tier2numcomparators(counter,counter2)</code> to <code>60+tier2numcomparators(counter,counter2)</code>. I first found this problem because it was being set to <code>81</code>, so it didn't just exceed <code>60+tier2numcomparators(counter,counter2)</code>, it exceeded <code>60+20</code>, with <code>tier2numcomparators</code> being bounded to <code>20</code>.</p>
  
  <p>I hope this isn't all too-much-information, but I felt it might be necessary to get you to understand just what sort of variables these are.</p>
  
  <p>So in my attempts to at least turn the data into valid data, I did the following:</p>
  
  <pre><code>for counter=1:size(tier2comparatorconnectionpoints,1)
   for counter2=1:size(tier2comparatorconnectionpoints,2)
    for counter3=1:size(tier2comparatorconnectionpoints,3)
     for counter4=1:size(tier2comparatorconnectionpoints,4)
      if tier2comparatorconnectionpoints(counter,counter2,counter3,counter4)&gt;60+tier2numcomparators(counter,counter2)
       tier2comparatorconnectionpoints(counter,counter2,counter3,counter4)=60+tier2numcomparators(counter,counter2);
      end
     end
    end
   end
  end
  </code></pre>
  
  <p>And that worked just fine. And then:</p>
  
  <pre><code>for counter=1:size(tier2comparatorconnectionpoints,1)
   for counter2=1:size(tier2comparatorconnectionpoints,2)
    for counter3=1:size(tier2comparatorconnectionpoints,3)
     for counter4=1:size(tier2comparatorconnectionpoints,4)
      if tier2comparatorconnectionpoints(counter,counter2,counter3,counter4)&gt;40+tier2numcomparators(counter,counter2)
       if tier2comparatorconnectionpoints(counter,counter2,counter3,counter4)&lt;60
        tier2comparatorconnectionpoints(counter,counter2,counter3,counter4)=40+tier2numcomparators(counter,counter2);
       end
      end
     end
    end
   end
  end
  </code></pre>
  
  <p>And that's where it said "Attempt to reference field of non-structure array".</p>