title: Populating a matrix with the values from array in MATLAB
body: <p>I have the following arrays,</p>
  
  <pre><code>Names = [string('abc') string('def') string('ghi') string('jkl')]
  SubName1 = [string('abc') string('jkl')]
  SubValue1 = [-1 1]
  SubName2 = [string('ghi') string('jkl')]
  SubValue2 = [-2 1]
  </code></pre>
  
  <p>The array named <code>SubValue1</code> contains the values that correspond to the keys(strings) in the array named <code>SubName1</code>.I want to compare <code>SubName</code> with <code>Names</code> and create a matrix that maps the key-value pair as follows</p>
  
  <pre><code>RowName  SubName1 SubName2
  abc          -1       0
  def           0       0 
  ghi           0      -2
  jkl           1       1
  </code></pre>
  
  <p>To obtain the above matrix I'm trying the following,</p>
  
  <pre><code>Index1 = find(ismember(Names,SubName1))
  Index2 = find(ismember(Names,SubName2))
  
  &gt;&gt;Index1 = [1 4];
  &gt;&gt;Index2 = [3 4];
  </code></pre>
  
  <p>I'm not sure how to proceed from here. Essentially, I am trying to fill the columns of the matrix with the values <code>SubValue</code> of the keys<code>SubNames</code> at the indices present in <code>Index</code>.</p>
  
  <p>Any suggestions?</p>