Introduction to Matlab By E. Noura Semary. Contents MATLAB Environment  Command window, Workspace, Path window, Editor window,and Figure window) Basic.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to Matlab
Matlab Programming Huajun Wang Department of Earth Sciences, Zhejiang University Jan 25,2012.
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.
ECEN/MAE 3723 – Systems I MATLAB Lecture 1. Lecture Overview  Introduction and History  Matlab architecture  Operation basics  Visualization  Programming.
Programming Environment S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: Control Flow.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Exam #3 Review: Comprehensive Exam Class 14.2 Palm Matlab Book Ch. 1-5.
Introduction to Matlab Οικονομίδης Δημήτρης
Introduction to Matlab. Entering Commands Constants and Functions >> pi ans = >> eps ans = e-016 >> sin(pi/2) ans = 1 >> log(1000) ans =
Introduction to MATLAB
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.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
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.
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.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
INTRODUCTION TO MATLAB LAB# 01
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
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.
Introduction to MATLAB
Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
OUTLINE Overview Numbers, variables and similar in Matlab
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
CSE123 Lecture 3 Files and File ManagementScripts.
Introduction to Matlab Part II 1Daniel Baur / Introduction to Matlab Part II Daniel Baur / Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Digital Image Processing Introduction to M-function Programming.
Introduction to Matlab Electromagnetic Theory LAB by Engr. Mian Shahzad Iqbal.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
CSE 455 : Computer Vision MATLAB 101 Getting Started with MATLAB.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Intro to Matlab Rogelio Long September 3, How to access MyDesktop Log in with your utep id and password.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
Introduction to Matlab Engr. Mian Shahzad Iqbal LAB NO.2
전자장 1 실험 - Matlab 사용법 - Photonic Systems Laboratory School of EE, Seoul National University Photonic Systems Lab School of EECS, S.N.U.
Matlab & Image processing toolbox Heejune Ahn SeoulTech Last updated Jan.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
Jake Blanchard University of Wisconsin Spring 2006.
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Introduction to Matlab
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
MATH 493 Introduction to MATLAB
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
آموزش مقدماتی نرم افزار MATLAB
Introduction to Matlab
Presentation transcript:

Introduction to Matlab By E. Noura Semary

Contents MATLAB Environment  Command window, Workspace, Path window, Editor window,and Figure window) Basic Functions: clc, clear, save, load, who, whos … Variables in MATLAB  Arrays Control flow (for – end, while – end, if – else – elseif – end, switch M-files Plotting Introduction to GUI Introduction to Image processing Toolbox

MATLAB Environment Command window Use Menus as an alternative to typing some commands Use of Toolbar for easy access to popular operations Status bar Command window Status of Caps, Num, and Scroll locks New M-file Open file Undo New Simulink Model Help Cut Paste Copy Workspace Browser Path Browser

MATLAB Environment Workspace Open the selected matrix Delete the selected matrix from the workspace Displays the total number of elements in the workspace and total size of them. Close the workspace browser size of the matrix Number of bytes in the matrix Name of the matrix Type of the matrix

MATLAB Environment Workspace Name of the matrix Current dimension of the matrix: User can change the dimensions of the matrix by simply type the dimensions he/she want Current Cell Current values: User can change the values o the matrix’s element by editing in the cell.

MATLAB Environment Path browser The current Directory The directories in the path The Files in the selected path. Add a new path Remove the selected path

MATLAB Environment Editor window Current line number Automatic Indenting Automatic Color Highlighting to Distinguish Different Elements The toolbar Names of the opened files in the editor New file Save file Copy Print Set/Clear break point Step in Continue List if functions in call stack Open file Cut Paste Help Clear all break points Single step Quit debugging

MATLAB Environment Figure window New figure Open an exciting figure Save the current figure Print Zoom the plot Rotate the plot Start / End the plot editor mode Draw an arrow in the plot Type a text in the plot Draw a line in the plot

Basic Functions Function nameFunction mean clcClear the command window clearClear workspace whoShow workspace whosShow workspace in details helpShow information about any function lookforSearch for a word in MATLAB files saveSaving workspace loadLoading saved workspace

Variables MATLAB variables are arrays Variable must be one word  myvariableaccepted  my variable not accepted Variable length is up to 31 character Variables must begin by a character MATLAB variables are case sensitive There are preserved variable names:

Variables ansDefault function output piPi = 3.14 epsVery small value infVery large value = ∞ as the result of (1/0) NaNWhen the result = 0/0 realminMinimum real number = × realmaxMaximum real number = × narginThe number of input parameters nargoutThe number of output parameters

Arrays : review Vector Array : (1 × n), (m ×1) Matrix : (m × n) Identity array (2×4) ->(3×2) -> (1×4) ->(3×1) ->

Arrays : review Assume You have A = B= A+B=A’ = 2A = = abcdefabcdef xyxy ax+by cx+dy ex+fy (m×k)(k×n)=(m×n)

Arrays : Marlab vision m=4m=[4] a=3*6m=[18] a=[1,4,6,8,9]a=[ ] M=[ ; ; ]  M(1)  2  M(6)  10  M(3, 4)  6  M(3, :)   M(:, 2)   M(1, 2:4)   M(2, 1:2:5)  M=

Standard arrays zeros zeros(3)= zeros(2,3)= ones ones(3)= ones(2,3)= eye eye(3)= eye(2,3)= magic magic(3) = randrand(3,4) = linspacelinspace (0,4,5)= [ ] linspace (1,2,3)= [ ] logspace logspace (0,4,5)= [ ] logspace (1,2,3)= [ ]

Array functions size size(N)=[3 3] sum sum(N) = [ ] length length(N)=[3] max max(N) = [9 7 8] det det(N)=-119 min min(N) = [1 0 3] diag diag(N)= flipud flipud(N)= invfliplr fliplr(N)= transpose (´ ) transpose(N)= rot90 rot90(N)= find find (N ==7 ) = 5 find (N == 10 ) = [] N=

Relational and Logical Operators Relational Operators Operator nameSymbolComment eq= equal ne~=not equal lt<less than gt>greater than le<=less than or equal ge>=greater than or equal Logical Operators and&logical and or|logical or not~logical not xorlogical exclusive or

Control Flow for – end for variable= expression statements end example: for i=1:10 for j=1:2:10 x(i) = i*2; y=jend

Control Flow while – end x=0; while (x<5) x=x+s; disp(x); end

Control Flow if – else – elseif – end a=6;% a=7; % a=10; if (rem(a,3)==0) a=a*3; elseif (rem(a,2)==0) a=a*2; else a=a*10; end disp (a);

Control Flow switch – case – otherwise – end x= input (‘The value of x:’); units= input (“Enter the unit of x: (Please Enter the unit between ‘ ‘) ’); switch units case (‘inch’,’in’) y=x*2.54 ; case (‘feet’,’ft’) y=x*2.54*12 ; case (‘meter’,’m’) y=x*100 ; case (‘millimeter’,’mm’) y=x/10 ; otherwise disp (‘Unknown unit’); end

Control Flow break for i=1:10 if (i>5) break; else a=a*4.5; end disp (a);

M-files 1. Scripts : Deal with the work space directly without inputs or outputs 2. Functions: Needs inputs and only the outputs are saved in the workspace. examples: function [output1,output2…]=function_name(input1,input2,…) function function_name(input1,input2,…)

M-files Function or script calling is done by typing the file name. The function file name must be the same as function name Function name must be one word Has a maximum of 31character size Starting by a character

M-files Assume a function: function [a,b,c]=my_function(x,y) is called as [b]=my_function(x,y,z); [a,b,c]=my_function(u); then b = a value x= u value

Math functions Basic functions triangular functions Approximation functions complex functionsconversion functions abs cos fix absdec2hex sqrt sin round angledec2bin mean tan floor conjdec2base power acos ceil imaghex2dec log asin rem realbin2dec log10 atanfloorbase2dec exp cscceilrad2deg max secremdeg2rad min cotcart2sph sort acsccart2pol asecpol2cart acotsph2cart cosh sinh tanh

Exercise 1. write a matlab program that sum a series begins by 2 and ends by 100 Use both for and while loops in separated m-files 2. write a switch – case program such that: if 35>=S>20 display ‘Hot Day’ if 20>=S>10 display ‘Nice Day’ if 10>=S>=0 display ‘Cold Day ‘ otherwise display ‘Out of Range’ That S is the sum of the array M, and M is: Random matrix of size 3×6 and has values between 0 and 2 A square matrix of size 3 and values between 1 and 9 A vector of equal elements =5 and size of 7 Identity matrix of size 10×10