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

Slides:



Advertisements
Similar presentations
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Advertisements

M AT L AB Programming: scripts & functions. Scripts It is possible to achieve a lot simply by executing one command at a time on the command line (even.
Functions in MatLab Create a new folder on your Z:drive called MatLab_Class24 Start MatLab and change your current directory to MatLab_Class24 Topics:
Input and Output ENGR 1181 MATLAB 5. Input and Output In The Real World Script files (which provide outputs given inputs) are important tools in MATLAB.
The Web Warrior Guide to Web Design Technologies
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
Computer Science 1620 Loops.
VBA Modules, Functions, Variables, and Constants
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Chapter 4 Sec. 4.1, 4.2, 4.4 Procedures (User-defined)
Topic 4 – Programmer- Defined Functions. CISC 105 – Topic 4 Functions So far, we have only seen programs with one function, main. These programs begin.
Airline On Time Performance Systems Design Project by Matthias Chan.
Lesson15. JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together.
Programmer Defined Functions Matthew Verleger. Windows It’s estimated that Window’s XP contains 45 million lines of code (and it’s over 10 years old).
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files called M- files. M-files are.
Functions 1 parameter, 2 return-values "Conversion of time format" One problem. 5 steps to solve it. 1.
Functions General Example (+1return values, +1 parameters) 1. The client's wish 2. Creating the function 1. Function's name, Parameter list, Return-info,
1 -Defined Functions 1. Goals of this Chapter 2. General Concept 3. Advantages 4. How it works Programmer.
1 Functions Advantages Name, parameters, return info Flow of the data when running functions Menus Functions Applying Functions to Real Projects.
Lists in Python.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
1 Tips for solving Project 1 Reactor SO 3 SO 2 +O 2.
Chapter 6 : Software Metrics
Annoucements Discovery Day ( sent this morning) – Wednesday, April 3 rd : Poster Presentation (Cafeteria) & Slide presentations (COA Atrium). For.
PROGRAMMING Functions. Objectives Understand the importance of modular programming. Know the role of functions within programming. Use functions within.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
1. Reminder of Symbols 2. Dialog Boxes 3. listdlg() 4. msgbox() 5. questdlg() 6. menu() Dialog Boxes Applications of Cell-Arrays 1.
File I/O 1. Goals of this chapter 2. General Concept, lots of examples 3. High-level I/O 1. Built-in functions that do everything in one step 4. Low-level.
Introduction to File I/O High-Level Functions 1.Data files 2."High level" File I/O 3.dlmread() 4.xlsread() 1.
Lab17 DUE NOW Deliverable 2 Quizzes continue next Lab. on Functions. 1.
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
CIS 338: Using Queries in Access as a RecordSource Dr. Ralph D. Westfall May, 2011.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
File I/O High-Level Functions 1. Definition 2. Is a High-Level function appropriate? 3. xlsread() 4. dlmread() 1.
2/13/2003CSCI 150: Introduction to Computer Science1 Introduction to Computer Science CSCI 150 Section 002 Session 9 Dr. Richard J. Bonneau IONA Technologies.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
Lecture 5 1.What is a variable 2.What types of information are stored in a variable 3.Getting user input from the keyboard 1.
Spreadsheet Models for Managers: Session 14 14/1 Copyright © Richard Brenner Spreadsheet Models for Managers Session 14 Using Macros II Function.
JavaScript, Fourth Edition
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
1. FINISHING FUNCTIONS 2. INTRODUCING PLOTTING 1.
Programmer-Defined Functions Advantages vs. Disadvantage 1.Definition and general Idea 2.Many Advantages 3.1 Disadvantage 1.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
FORTRAN History. FORTRAN - Interesting Facts n FORTRAN is the oldest Language actively in use today. n FORTRAN is still used for new software development.
-Defined Functions 1. Goals of this Chapter 2. General Concept 3. Advantages 4. Vocabulary 5. Examples 6. General Template – Applications 1. Definitions,
Chapter 8 Functions in Depth. Chapter 8 A programmer-defined function is a block of statements, or a subprogram, that is written to perform a specific.
Early File I/O To help you get started with your final project 1. Definition of “high level” 2. Is using a High Level function appropriate? 3. xlsread()
ENG College of Engineering Engineering Education Innovation Center 1 Functions 1 in MATLAB Topics Covered: 1.Uses of Functions Organizational Tool.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Introduction to TouchDevelop Lesson 3 – Comments & Lists Created by S. Johnson
Programming Fundamentals Enumerations and Functions.
JavaScript 101 Lesson 6: Introduction to Functions.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Is your Flight on Time? Power BI. 6 years - Currently working as an Senior DBA in Microsoft SQL Server - Business Intelligence (MSBI) group at UPS 40.
Matlab Training Session 4: Control, Flow and Functions
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
CPS125.
Presentation transcript:

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

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

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

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

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

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 = …

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!

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!!!!!

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

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 = ( ) %  Numerical values  Strings  Numerical Arrays  Cell-Arrays  … anything!

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

8. Application: Shortening Codes! Travelling Delays? Who/What’s to blame??? 12

8. Application: Shortening Codes! Excel sheets. Arriving Flights/Delayed Flights/Reasons

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

Solve for.. 15

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

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

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

Main file %Airline On-Time Statistics and Delay Causes %by Caroline % 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

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

Quick reminder sum(matrix) sums each COLUMN. x = >> sum(x) ans =

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