1 / 22

Add to your agenda!

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”

zhen
Download Presentation

Add to your agenda!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Add to your agenda! • Discovery Day. Wednesday, April 3rd – 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 3rd, 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 Dr. Mote

  2. Programmer-DefinedFunctions (2) Basics & Advantages Vocabulary & Order MATLAB follows Review of the general syntax (i.e. setup) Full example

  3. 1. BASICS • A functionis 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

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

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

  6. 2. Review of vocabulary Main script file • 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 Function definition Function call, passarguments Return info Variable = …

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

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

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

  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) 1. 2. .. function <return info> = <function name>(<parameters>) % <documentation/help> % <author etc..> <function body> • Numerical values • Strings • Numerical Arrays • Cell-Arrays • … anything!

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

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

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

  14. 21 columns.. Only a few useful today

  15. Solve for.. • Percentage of flights delayed • Percentage of those flights delayed due to carrier’s fault • Percentage of those flights delayed due to weather • Percentage of those flights delayed due to NAS • Percentage of those flights delayed due to security • Percentage of those flights delayed due to late flights • Percentage of flights arrived on time • Present result in table • If time, present results in pie chart

  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.

  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 <author goes here>

  18. extractCorrectData.m functionon_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 <author would go here>

  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

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

  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

  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?

More Related