Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)

Slides:



Advertisements
Similar presentations
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Advertisements

Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.
CS101: Introduction to Computer programming
Matrix Manipulation and 2D Plotting
Using Macros and Visual Basic for Applications (VBA) with Excel
Al-Amer An Introduction to MATLAB Lesson 2: M-files Dr. Samir Al-Amer Term 061.
Using Excel for Data Analysis in CHM 161 Monique Wilhelm.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
© Copyright 2000, Julia Hartman 1 Scatterplot Output: Editing the Graph You can edit the output to display the entire variable label. Click inside the.
Introduction to LabVIEW Seth Price Department of Chemical Engineering New Mexico Tech Rev. 10/5/14.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Before modifying and saving: A certificate may be printed when a student answers the last question correctly (Slide 35). A macro is used to print out.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
Visual Basic Chapter 1 Mr. Wangler.
Python Programming Fundamentals
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington While loops and the UI API.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
Shell Scripting Introduction. Agenda What is Shell Scripting? Why use Shell Scripting? Writing and Running a Shell Script Basic Commands -ECHO - REM.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
GUI development with Matlab: GUI Front Panel Components 1 GUI front panel components In this section, we will look at -GUI front panel components -Programming.
ENGR 1320 Final Review - Programming Major Topics: – Functions and Scripts – Vector and Matrix Operations in Matlab Dot product Cross product – Plotting.
Automating Database Processing
Advanced Stata Workshop FHSS Research Support Center.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Post-Processing Output with MATLAB Claudia Fricke Institute of Petroleum Engineering, Heriot Watt University.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
I Power Higher Computing Software Development Development Languages and Environments.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
A simple classification problem Extract attributes Pattern Pattern recognition decision x C1 C2.
Files: By the end of this class you should be able to: Prepare for EXAM 1. create an ASCII file describe the nature of an ASCII text Use and describe string.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
9.3 – Linear Equation and Inequalities 1. Linear Equations 2.
Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal.
EXCEL GRAPHING *Basic Graphing Steps* by A.B. -NNHS.
Using MIT Scratch for Programming and Control Exercise 1 Creating movement Year 11 DTG 2012.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
Extending MATLAB Write your own scripts and/or functions Scripts and functions are plain text files with extension.m (m-files) To execute commands contained.
Introduction to Literate Programming in Matlab 2WN50 – Week programming-in-matlab.pptx?dl=0.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Chapter 6 Controlling Program Flow with Looping Structures.
Excel Tutorial 8 Developing an Excel Application
Visual Basic.NET Windows Programming
Release Numbers MATLAB is updated regularly
Programming & Scratch.
Computer Application in Engineering Design
Matlab Training Session 4: Control, Flow and Functions
Lecture 25.
Program and Graphical User Interface Design
Program and Graphical User Interface Design
Lecture 1: Introduction
When I want to execute the subroutine I just give the command Write()
Exploring Microsoft Excel
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Coding Concepts (Basics)
Instructions for Windows users:
Introduction to Matlab LAB 4
Instructions for Windows users:
Instructions for Windows users:
Structures- case, sequence, formula node
CSCI N207 Data Analysis Using Spreadsheet
Scripts In Matlab.
Input and Output Python3 Beginner #3.
Presentation transcript:

Scripts and Flow Control

Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions) – Text files that contain lists of commands

Script files are saved in plain text and end in.m (for example example.m) A separate editor window is used to edit scripts A new script file can be created by: – clicking the new script button (top left) – Typing edit name_Of_Your_Script.m – File -> New -> Script

Contain a list of commands, which is executed in order. Access to the workspace Execute by typing name of script in command line (when in the same directory) Or by clicking the green arrow at the top of the editor

Simple Example

Write a script that – Plots the following equation on the same graph, adds a title and labels the axes. y = x^2 -4 y = sin(2x)-1

Task Create a script file (Called testScript) that – Plot the following equations on the same graph (different colours) – Add appropriate titles, labels and legend – Solve the system of equations – Plot the solution on the same graph

Flow Control Within a script (or function) you might want to repeat a series of commands (for and while loops) or choose between a series of commands (if and case statements)

If Choose between 2 ( or more ) blocks of code

Can use a variety of conditions

For For loops allow you to loop over commands a pre defined number of times (with an iterator)

While Loops over some code until the condition is false

What does the following script do?

Task Write a script implements the following Starting from a user supplied starting n (use the input function) Return the sequence and the number of iterations