title: What does the MATLAB error "scalar structure required for this assignment" refer to in this statement?
body: <p>I have a structure, <code>space_averaged_data</code>, which has a member <code>Ps</code> that is defined as a cell array with a variable length. I assign values to this cell array after creating the structure as shown below (I've omitted the other structure fields for clarity):</p>
  
  <pre><code>Ps = cell( 1, num_p );
  for p = 1:length(Ps)
      Ps{p} = rand( 150, 1000 );
  end
  
  space_averaged_data = struct( 'Ps', cell( 1, length(Ps) ) );
  
  for p = 1:length(Ps)
      space_averaged_data.Ps{p} = mean( Ps{p}, 2 );
  end
  </code></pre>
  
  <p>If the value of <code>num_p</code> is 1 (i.e., the cell array isn't an array), everything works just fine. If the value of <code>num_p</code> is greater than 1, however, I get the following error:</p>
  
  <pre><code>Scalar structure required for this assignment.
  Error in:
      space_averaged_data.Ps{p} = mean( Ps{p}, 2 );
  </code></pre>
  
  <p><strong>What is the non-scalar structure in this assignment?</strong> I have no idea what the error is referring to.</p>