I am taking a MATLAB programming class and we are currently working on a project which uses a database called Project2 of several structs of airline flight data (all 1 x N). One exercise requires us to create a function that identifies the number of flights segments (housed in the flights struct) that used the Boeing 737-800 aircraft. Below I have included the code for the function I created (NOTE: The format of the first line is such that was dictated in the instructions and must remain that way). Although this function seems to work and be free of bugs, it consistently returns a result of 0 and I cannot figure out why. Can anyone help? Suggestions for fixing the problem and/or cleaning up the code would be greatly appreciated!
function total = Problem2 (flights, aircraft, airlines, airports)
load Project2
id=findAircraftID (aircraft, Boeing 737-800)
seg=0;
for jj = 1:length(flights)
if (strcmp (flights(1,jj).aircraft_id, id))
seg=seg+1
end
end
fprintf ('A total of %d flight segments used the Boeing 737-800 aircraft.\n', seg)
end
function id=findAircraftID (aircraft, AircraftName)
id=0;
for ii=1:length(aircraft)
if (strcmp (aircraft(1,ii).name, AircraftName))
id=ii;
return;
end
end
end