Presentation is loading. Please wait.

Presentation is loading. Please wait.

Add to your agenda! Discovery Day. Wednesday, April 3 rd – all day – Poster Presentation (Cafeteria) & Slide presentations (COA Atrium). For example: “Formula.

Similar presentations


Presentation on theme: "Add to your agenda! Discovery Day. Wednesday, April 3 rd – all day – Poster Presentation (Cafeteria) & Slide presentations (COA Atrium). For example: “Formula."— Presentation transcript:

1 Add to your agenda! Discovery Day. Wednesday, April 3 rd – all day – Poster Presentation (Cafeteria) & Slide presentations (COA Atrium). For example: “Formula Hybrid High Voltage System” “Development of Next Generation IPMC Actuator for Flapping Wing UAV” “Mt. Everest Skydiving Research” “Tolerance for Ambiguity of Air Traffic Management Students” TOMORROW! Wednesday, April 3 rd, 7PM, IC Auditorium – “Innovation: Risk are necessary!” COE Forum. Monday, April 8th, 6PM, Lehman Atrium – free food! – Each college has representatives on the SGA and they host a forum for their college. Answer questions, give opinions! Arts & Science, Aviation. Business, Engineering 1 Dr. Mote

2 Programmer-Defined Functions (2) 1.Basics & Advantages 2.Vocabulary & Order MATLAB follows 3.Review of the general syntax (i.e. setup) 4.Full example 2

3 1. BASICS A function is nothing but a “keyword” – If that keyword is MATLAB’s, it is a “built-in” function – If the programmer (you) created the.m file associated with the keyword, it is a “programmer-defined” function 3

4 1. Review of advantages 1.Focus 2.Independence (they can be tested separately) 3.Memory efficiency 4.Easier to debug the overall code 5.Clarity 6.Re-usability 7.Modularity 4

5 1. “dis”-advantage Only 1 disadvantage: a lot more.m files within your directory 5

6 2. Review of vocabulary Main script file: The script file that contains the original overall project. Function definition: the function header and the actual lines of code the function has to execute. (a little file for each new keyword) Function call: the command that calls upon the execution of the code that is inside the function definition – Usually placed within the main script file, but can also be within another function definition. (A function CAN call another function you made!) Passing arguments: giving inputs to the function definition. Return info: final variables that the function definition calculated and gives back Collection variables: The variables which receive the return info 6 Function definition Main script file Function call, pass arguments Return info Variable = …

7 Vocabulary is important! 7 “Function call” Professors & tutors will use these words! (instead of the “thingy”) “Function parameters” (5) Passed “arguments” (2) “Return-info” Collecting the “Return-value” 50 lines of “documentation” “Function file” In a ain script OR another function file OR the command window! 444 lines of code!

8 Common mistake The “function call” is NOT the “function’s name” 8 This file is the “function definition” Here are 3 examples of “function calls” The name of the function is changeToLetter() regardless!!!!!

9 Order MATLAB follows to communicate 9 Execute 444 lines of code! Pass the arguments. Replaces the parameters. Assign a value to the return-info Answer = …. “Return” the info Collect the returned value

10 3. General Syntax In a separate.m file: Variables used in return-info, parameters, collecting return values, and arguments can be:  Hardcoded (example: 32)  Variables (example: age) 10 function = ( ) % 1. 2...  Numerical values  Strings  Numerical Arrays  Cell-Arrays  … anything!

11 Example: askForValidate.m Re-usability 11 Any questions overall?

12 8. Application: Shortening Codes! Travelling Delays? Who/What’s to blame??? 12 http://www.transtats.bts.gov/OT_Delay/OT_DelayCause1.asp?pn=1

13 8. Application: Shortening Codes! Excel sheets. Arriving Flights/Delayed Flights/Reasons 13.. 2010 2011 2012 2013

14 21 columns.. Only a few useful today 14 1, 2Year and month 3, 4Carrier and its name 5, 6Airport, and its name 7arr_flights Count of flights 8arr_del15 Count of flights delayed (>15minutes) 9carrier_ct Late due to carrier (maintenance or crew problems, aircraft cleaning, baggage loading, fueling, etc) 10weather_ct Late due to weather (Significant meteorological conditions ) 11nas_ct Late due to National Aviation Delay System (non-extreme weather conditions, airport operations, heavy traffic volume, and air traffic control) 12security_ct Late due to evacuation of a terminal or concourse, re-boarding of aircraft because of security breach, inoperative screening equipment and/or long lines in excess of 29 minutes at screening areas 13late_aircraft_ct A previous flight with same aircraft arrived late, causing the present flight to depart late. 14arr_cancelled Count of aircraft cancelled 15arr_diverted Count of aircrafts diverted 16 arr_delay 17 carrier_delay 18weather_delay 19nas_delay 20security_delay 21late_aircraft_delay

15 Solve for.. 15

16 2 Functions to create [nbs, headings]=extractCorrectData(fileChosen); Depending on the file chosen (2010? 2009?...), get rid of all the lines that have blanks, and only return the nbs and the headings needed. flights_on_time = analyze(headings, nbs); Given the headings and numbers needed, calculate all percentages and display in a table. Calculate and return the % of flights on time. 16

17 extractCorrectData.m function [nbs, headings]=extractCorrectData(fileChosen) %USE AS: [nbs, headings]=extractCorrectData(fileChosen); % Depending on the file chosen (2010? 2009?...), get rid % of all the lines that have blanks, and only return the % nbs and the headings needed. % by 17

18 extractCorrectData.m function on_time = analyze(headings, nbs) %USE AS: on_time = analyze(headings, nbs); % Given the headings and numbers needed, calculate all percentages and % display in a table. Calculate and return the % of flights on time. % by 18

19 Main file %Airline On-Time Statistics and Delay Causes %by Caroline %http://www.transtats.bts.gov/OT_Delay/OT_DelayCause1.asp?pn=1 clc clear repeat = 1; %force loop to start while repeat ==1 clc %let user pick file myFile = uigetfile('*.*'); %get rid of bad data, and useless columns %calculate percentages/display table %show year and flight on time year = fprintf('Flights were %.2f% on time in %s.\n',flights_on_time,year) %ask user to repeat repeat = input('Choose another file? (1 for yes, anything else quits): '); end 19

20 Online App shows ALL data I just wanted to focus on the “not on time” 20

21 Quick reminder sum(matrix) sums each COLUMN. x = 17 19 6 20 19 13 11 4 3 2 20 20 >> sum(x) ans = 39 34 37 44 21

22 Improvements? Note how LONG it takes for MATLAB to process excel sheets. How about combining ALL years into 1 xls sheet? >> memory issues How about putting each year into a separate sheet? Giving the user the possibility to analyze only 1 airline? 22


Download ppt "Add to your agenda! Discovery Day. Wednesday, April 3 rd – all day – Poster Presentation (Cafeteria) & Slide presentations (COA Atrium). For example: “Formula."

Similar presentations


Ads by Google