Function with two outputs and multiple references
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to create a function "airportStatistics" that takes a Destination (Airport 1, Airport 2...,Airport 20) as an input but i'm not sure how to go about it. The function must then return the name of the Destination (e.g. London) and the weekly number of passengers per destination. I have imported two excel-files containing the material. The first "Destination" contains the Destination in the first column and the name in the second:
'Destination' 'Airport Name'
'Airport 4' 'Hamburg International Airport'
'Airport 7' 'Sevilla International Airport'
'Airport 2' 'London Airport'
etc.
The second file contains the Destinations in the 3rd column one for each departure per day
'Destination'
'Airport 19'
'Airport 11'
'Airport 3'
'Airport 8'
'Airport 1'
'Airport 14'
etc.
In the function i must take into account that the destinations in the 2nd file only account for 1 day but the function has to return departures per week.
4 comentarios
John D'Errico
el 23 de Abr. de 2017
How to do it? You start writing!
First, read in the xls file into MATLAB.
Start by writing a function header, that takes the necessary input, passed in as arguments.
Then look at the list of destinations. Count how many departures there are for each airport.
You won't get anywhere at all until you start making an effort. Then attack each part of the problem until you are done.
Respuestas (1)
Image Analyst
el 23 de Abr. de 2017
I'd use readtable() to get the results in a table instead of a cell array. Then I'd probably use ismember() to find out what rows you need to deal with. The function line would look like
function [destinationAirport, numPassengersPerWeek] = airportStatistics(destinationAirport)
though I'm not sure if destinationAirport is just one airport or a list of a bunch of them. Also not sure why you're returning it from the function since you already have it, unless you're going to change it for some reason inside the function.
4 comentarios
Image Analyst
el 24 de Abr. de 2017
I can't really figure all that out in my head. I suggest you use the debugger: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ just like I would do. I don't have your data so I can't do it, but you can do it just as well as I can.
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!