title: Displaying certain elements of a structure array
body: <p>I have a quick question to ask.
  I am tryig to create a function called 'passavg_structure' that takes as an input argument an airspace structure array (which will be shown below), and outputs the average amount of passengers heading to the specified city. </p>
  
  <p>The airspace structure array looks like this: </p>
  
  <pre><code>&gt;&gt; airspace(1)
  
  ans = 
  
       Flight_Number: 'BF 123'
               Speed: 515.2000
             Heading: 90
          Passengers: 154
                Crew: {'Behnam'  'Jane'  'Jill'  'Ning'}
         Destination: 'Montreal'
                Feet: 22000
  Latitude_Longitude: [50 100]
  
  &gt;&gt; airspace(2)
  
  ans = 
  
       Flight_Number: 'VSO 456'
               Speed: 99.6000
             Heading: 270
          Passengers: 270
                Crew: {'Frances'  'Jake'  'Jaiwei'}
         Destination: 'Los Angeles'
                Feet: 21000
  Latitude_Longitude: [50 80]
  
  &gt;&gt; airspace(3)
  
  ans = 
  
       Flight_Number: 'BF 8421'
               Speed: 1.5057e+03
             Heading: 170
          Passengers: 0
                Crew: {'Giuseppe'  'Susan'}
         Destination: 'Calgary'
                Feet: 33000
  Latitude_Longitude: [60 80]
  
  &gt;&gt; airspace(4)
  
  ans = 
  
       Flight_Number: 'AB 896'
               Speed: 500
             Heading: 90
          Passengers: 132
                Crew: {'Hao'  'Ashraf'  'Sue'}
         Destination: 'Montreal'
                Feet: 33000
  Latitude_Longitude: [50 100]
  </code></pre>
  
  <p>So what I am trying to do is to iterate through the names of the airspace, and if it equals the name given by the input argument of the function, then it will find where the name occurs in the structure array and add on the passenger numbers, and then divide number of times the name was used, to get the average. My incomplete code is below: </p>
  
  <pre><code>function output = passavg_structure(airspace,name)
  output = 0;
  [a, b, c, d] = airspace(:).Destination;
  for k = {a,b,c,d}
  if strcmp(k,name) == 1
      output = airspace().Passengers;
  else 
      output = 0;
  end 
  output = output/;
  end
  </code></pre>
  
  <p>Im lost on how to find the loaction as to where the matched name occurs in the structure array. I feel like that is my problem with my code and thereore it is incomplete since I'm not sure on how to do that. </p>
  
  <p>For example, lets say we did:</p>
  
  <pre><code>passavg_structure(airspace,'Montreal')
  </code></pre>
  
  <p>The output would be = 143, since it added the passengers from where 
  Montreal occured and divided it by 2, since Montreal occured twice. </p>
  
  <p>Any help on this would be greatly appreciated!</p>
  
  <p>Thank you all. </p>