title: How can I combine two arrays of vector components into an array of vectors in matlab
body: <p>I have two arrays of the same size, <code>ux</code> and <code>uy</code>, which I want to combine into a cell array of vectors such that <code>U(1,1)</code> contains a vector composed of <code>uy(1,1),ux(1,1)</code> and `numel(U)=numel(ux)=numel(uy)'</p>
  
  <p>The components <code>ux</code> and <code>uy</code> represent the unit vector of the image gradient. The component arrays are created by elementwise multiplication:</p>
  
  <pre><code>ux = I1x./I1mag;
  uy = I1y./I1mag;
  </code></pre>
  
  <p>I need to be able to access each vector multiple times, and call them as arguments of <code>dot</code> and <code>cross</code> and making an array of vectors would be faster and more convenient than creating an ad hoc vector for each one on every iteration where it is called.</p>
  
  <p>Thanks</p>
  
  <p>Edit for further clarity:</p>
  
  <p>suppose I have an array</p>
  
  <pre><code>uy = (1,2,3;4,5,6);
  </code></pre>
  
  <p>and another array of the same size</p>
  
  <pre><code>ux = (9,8,7;6,5,4);
  </code></pre>
  
  <p>I need the yx vectors, so for our example that's</p>
  
  <p>([1,9], [2,8], [3,7]; [4,6], [5,5], [6,4])</p>
  
  <p>What's the most efficient way to do that, please? I'm going to get dot products of each pixel with its neighbours and vice versa, so each vector will be used 16 times and the full arrays contain on the order of 10^4 or 10^5 elements... </p>
  
  <p>Thanks for your continued help.</p>