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.
The airspace structure array looks like this:
>> 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]
>> 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]
>> 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]
>> 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]
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:
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
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.
For example, lets say we did:
passavg_structure(airspace,'Montreal')
The output would be = 143, since it added the passengers from where Montreal occured and divided it by 2, since Montreal occured twice.
Any help on this would be greatly appreciated!
Thank you all.