The Hong Kong Polytechnic University Industrial Centre 2008 1 MatLAB Lesson 1 : Overview & Environment Edward Cheung Room W311g.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to M ATLAB Programming Ian Brooks Institute for Climate & Atmospheric Science School of Earth & Environment
Introduction to Matlab
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
MATLAB ME1107 Y Yan Reference: MATLAB for Engineers by Holly Moore (Pearson Prentice Hall)
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Introduction to MATLAB
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
Lecture 13: M/O/F/ for Engineering Applications - Part 1 BJ Furman 26NOV2012.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
Introduction to MATLAB
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.
IC3003 B ASIC S CIENTIFIC C OMPUTING Lecture 1 Monday 08:30-11:30 U204a.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
INTRODUCTION TO MATLAB LAB# 01
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
A Brief introduction to MatLAB ($50 - $99 for students)
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
CMPS 1371 Introduction to Computing for Engineers MatLab.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
EGR 115 Introduction to Computing for Engineers Introduction to MATLAB Friday 29 August 2014 EGR 115 Introduction to Computing for Engineers.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Matlab for Engineers Matlab Environment Chapter 2.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Lecture 12: M/O/F/ for Engineering Applications B Burlingame 27 April 2016.
An Introduction to Programming in Matlab Emily Blumenthal
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
ECE 1304 Introduction to Electrical and Computer Engineering
Lecture: MATLAB Chapter 1 Introduction
MATLAB Basics Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
Use of Mathematics using Technology (Maltlab)
Lecture 2 Introduction to MATLAB
Matlab Basic Dr. Imtiaz Hussain
Experiment No. (1) - an introduction to MATLAB
Chapter 2 MATLAB Environment
Presentation transcript:

The Hong Kong Polytechnic University Industrial Centre MatLAB Lesson 1 : Overview & Environment Edward Cheung Room W311g

2 Introduction MatLAB stands for Matrix Laboratory A Scientific calculator A programming language Good in Matrix calculation and graph plotting written in Fortran and rewritten in C  common programming languages in Science & Engineering  MatLAB becomes a standard tool for scientists & engineers Other computational tools; Maple, Mathematica, MathCad Only Minor change since MatLAB 6 Latest version is MatLab ver.7 (R2008a/b)

3 What we’ll cover?

4 Start Up – UI, Windows & Environment Interactive, interpretative & programmable Command, command history & workspace window Transfer any command from the command history window to the command window by double clicking (also executes the command) or by click & drag Launch Pad shows all available products and launch them Workspace window keep track the variables defined in the programme MatLAB 7 provided more information on variable like size, bytes, Max, Min, etc. in addition to Name, Value and Class (right click at the Workspace Browser) The default data type use in calculation is double precision floating point numbers

5 Workspace Browser Data is not save on exit unless execute “save Workspace As” from the File Menu Or using the save function to save all to a MAT-file >>save % by default, stores all workspace variables in a binary format in the current directory in a file named matlab.mat Can also save in ASCII format (readable but larger in size) >> Save filename.dat {variables} –ascii >> help save

6 Some keys Arrow key to run previous command clear screen of command window while keeping history >> clc >> clear % delete all variables  Command History Window can be cleared from Edit Menu Who & whos  give variable information in the command window Double clicking on a variable listed in the workspace window launches a document window called  the array editor A semicolon (;) at the end of a command will suppress the output, try >>x=9; x=x+9

7 Keywords You can redefine keywords >iskeyword % list reserved names You can redefine function as variables Example >> sin=3; >> sin(90) ??? Index exceeds matrix dimensions. >> which sin % check if sin is a function sin is a variable. >> clear sin % reset sin back to a function >> which sin % check again sin is a built-in function. Most easy overlook is redefining i & j

8 Helpful Commands >> Help % give help topics >> Lookfor %Search all M-files for keyword Try >> help format >> format compact % no linefeed >> format loose % default with linefeed >> format long % fixed-pt 15 digits >> format rat % rational format >> format blank % 2 decimal places  e.g. Get pi with the above format No matter what format is selected, calculation are performed using double precision floating point numbers. >> format % reset to format default

9 Variables Variables are created with >> variable = expression Type of variables  Scalars  Vectors  Matrices  Strings

10 Variables All name must starts with a letter No special character except underscore, case sensitive X≠x Convention – lowercase for variable & uppercase for constants but there are exceptions (eg speed of light=c) MatLab 6 max length 31 characters  Namelengthmax = 63 (ver. 7 function) isvariablename – check the validity of variable name (boolean T=1; F=0), for example:- >> isvarname polyu >> isvarname poly-u >> isvarname poly_u

11 Scalar Variables A variable with one row and one column Creating scalars >> A=1; %creates a scaler >> B=1:10; % creates a vector >> C=[1,2;3,4]; creates a 2D matrix end can be use to terminate a function or indicate last array index >> iskeyword end ans = 1 >> x=[2 3 4]; >> x(end+2)=7 x =

12 Scalar Operations >> x=5; >> y=3; >> z=x+y; >> s=x-y; >> a=x*y; >> d=x/y; >> d=y\x; >> p=x^y;

13 Vector A vector can be a column matrix (nx1)or row matrix (1xn) Helpful function in vector creation Ones() & Zeros() >> x=ones(1,5) x = >> x=zeros(5,1) x = 0

14 Create vector with scaling between elements >> x=linspace(1,5,5) x = >> y=logspace(1,5,5) y = >> y(3) % addressing vector elements ans = 1000 >> x(7)=-9 % increase the size of a vector x = Array operators: Dot multiply or dot star.* -array multiplication dot divide or dot slash./ -array division Dot power or dot caret.^ -array power

15 The colon operator Create vector from a matrix >>x= xbegin:dx:xend Xbegin & xend = begin & end value of x dx = optional increment (default is 1) Example:- >> x=1.1:5.1 x = Transpose operator creates a column vector >> x=(1:5)' x = >> b=0:2:10 % a vector starts at 0 ended at 10 with an increment 2

16 Matrices In MatLab, a matrix is a variable with more than 1 row and 1 column  Variables with a dimension 1x1 is a scalar Example:- create a 2x2 matrix and assigned to variable A >> A=[1 2;3 4] A = (looks like a table) >> A=[1 2 3;4 5 6;7 8 9] A = >> A(2,3) ans = 6

17 Matrix Sum >> lookfor sum TRACE Sum of diagonal elements. CUMSUM Cumulative sum of elements. SUM Sum of elements. SUMMER Shades of green and yellow colormap. ………. >> help sum SUM Sum of elements. For vectors, SUM(X) is the sum of the elements of X. For matrices, SUM(X) is a row vector with the sum over each column. ………

18 String >> a='polyu'; >> b=' '; >> c='ic'; >> [a b c] ans = polyu ic >> disp(a) polyu >> % display array >> disp('Solution 1.1') Solution 1.1

19 MatLab File Types M-file  plain ASCII text that is interpreted at run time  parsed once and "just-in-time" compiled  best for development as well as platform independency File Menu  New  M-file  % = comment statement >> what % give M-files & Mat files in current directory Filename restriction  No special character including space except underscore ‘_’

20 MatLab File Types Pcode file  a preparsed and encoded version of the M-file  Fast function load time; for large file, this is important  hide the source code from others.  Cannot convert Pcode back to the M-file source  Pcode is also platform independent MEX file  native C or C++ files that are dynamically linked directly into the MATLAB application at runtime.  Need to be compiled for different system hardware  Fastest runtime but can crash the MatLab application