title: Operating on a vector from 4D matrix in Matlab
body: <p>I am trying to do an operation like the following for every pixels in an image:</p>
  
  <p><img src="https://i.stack.imgur.com/zXjNO.gif" alt="equation"></p>
  
  <p>A is x*y*4 matrix, w is simply an 1x9 vector.</p>
  
  <p>I have a matrix L which is 200x200x4x9.</p>
  
  <p>The first two dimensions of L are (x,y) location of pixels. Each location has 4 different sub-pixel (the third dimension). Every sub-pixel has a vector m, which is the last dimension is the m in my equation.</p>
  
  <p>I plan to get the result for the 1st sub-pixel for the whole image, that's what I tried:</p>
  
  <pre><code>A (:,:,1) = w * L (:, :, 1, :)  ====&gt; Inputs must be 2-D, or at least one input must be scalar.
  A (:,:,1) = w * L (:, :, 1, :)' ====&gt; Transpose on ND array is not defined.
  A (:,:,1) = w * reshape (L (:, :, 1, :), 1, 9)' ===&gt; To RESHAPE the number of elements must not change.
  </code></pre>
  
  <p>If I just print L (1,1,1,:) I get values of individual elements (does not look like a vector):</p>
  
  <pre><code>ans(:,:,1,1) = 0.8980
  ans(:,:,1,2) = 0.8065
  ans(:,:,1,3) = 0.8471
  ans(:,:,1,4) = 0.7607
  ans(:,:,1,5) = 0.7175
  ans(:,:,1,6) = 0.9020
  ans(:,:,1,7) = 0.8100
  ans(:,:,1,8) = 0.7640
  ans(:,:,1,9) = 0.8135
  </code></pre>
  
  <p>EDIT: For reference,</p>
  
  <pre><code>Size(A) = [200 200 4]
  Size(L) = [200 200 4 9] 
  Size(w) = [1 9]
  </code></pre>
  
  <p>EDIT: That's how I do it using loops</p>
  
  <p><img src="https://i.stack.imgur.com/WGmFp.png" alt="loop"></p>