Function with two outputs and multiple references
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
John D'Errico
2017-4-23
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.
回答(1 个)
Image Analyst
2017-4-23
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 个评论
Image Analyst
2017-4-24
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!