MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

Similar documents
EGR 111 Introduction to MATLAB

Introduction to MATLAB

Introduction to MATLAB

Desktop Command window

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

PART 1 PROGRAMMING WITH MATHLAB

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Introduction to MATLAB LAB 1

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

MATLAB TUTORIAL WORKSHEET

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

MATLAB Tutorial Matrices & Vectors MATRICES AND VECTORS

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Course Layout. Go to follow instr. Accessible within campus (only for the first download)

2.0 MATLAB Fundamentals

MATLAB Project: Getting Started with MATLAB

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

Introduction to Matlab

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

AN INTRODUCTION TO MATLAB

1 Overview of the standard Matlab syntax

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

MATLAB Project: Getting Started with MATLAB

6.094 Introduction to MATLAB January (IAP) 2009

To start using Matlab, you only need be concerned with the command window for now.

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

(Creating Arrays & Matrices) Applied Linear Algebra in Geoscience Using MATLAB

Chapter 2. MATLAB Fundamentals

A Guide to Using Some Basic MATLAB Functions

MATLAB. Devon Cormack and James Staley

Vectors and Matrices. Chapter 2. Linguaggio Programmazione Matlab-Simulink (2017/2018)

University of Alberta

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to Engineering gii

Introduction to Matlab

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

CME 192: Introduction to Matlab

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

ENGR 1181 MATLAB 02: Array Creation

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

Lecture 15 MATLAB II: Conditional Statements and Arrays

Programming in Mathematics. Mili I. Shah

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

1 Introduction to Matlab

MBI REU Matlab Tutorial

Computer Programming ECIV 2303 Chapter 1 Starting with MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering

How to learn MATLAB? Some predefined variables

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

Introduction to MATLAB

Introduction to MATLAB Programming

MATLAB GUIDE UMD PHYS401 SPRING 2012

An Introduction to Numerical Methods

Dr Richard Greenaway

MATLAB/Octave Tutorial

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

Grace days can not be used for this assignment

Matlab Programming Introduction 1 2

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

Digital Image Analysis and Processing CPE

A General Introduction to Matlab

Introduction to MATLAB

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Introduction to Matlab

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

Matlab Tutorial. Get familiar with MATLAB by using tutorials and demos found in MATLAB. You can click Start MATLAB Demos to start the help screen.

Computer Project: Getting Started with MATLAB

The value of f(t) at t = 0 is the first element of the vector and is obtained by

Introduction to MATLAB

ECE Lesson Plan - Class 1 Fall, 2001

Introduction to MATLAB

Introduction to MATLAB

FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx

Introduction to MATLAB

Introduction to MATLAB

McTutorial: A MATLAB Tutorial

MATLAB BASICS. M Files. Objectives

Some elements for Matlab programming

MATLAB Modul 2. Introduction to Computational Science: Modeling and Simulation for the Sciences, 2 nd Edition

Lab #1 Revision to MATLAB

Lecture 1: Hello, MATLAB!

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

Engineering Innovation Center MATLAB Basics

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

Dr Richard Greenaway

Finding, Starting and Using Matlab

CITS2401 Computer Analysis & Visualisation

Dr. Nahid Sanzida b e. uet .ac.

Lecture 2: Variables, Vectors and Matrices in MATLAB

Unix Computer To open MATLAB on a Unix computer, click on K-Menu >> Caedm Local Apps >> MATLAB.

MATLAB SUMMARY FOR MATH2070/2970

Transcription:

MATLAB Basics Stanley Liang, PhD York University Configure a MATLAB Package Get a MATLAB Student License on Matworks Visit MathWorks at https://www.mathworks.com/ It is recommended signing up with a student email The MATLAB Student package MATLAB and Simulink Student Suite Image Processing Toolbox Statistics and Machine Learning Toolbox Data Acquisition Toolbox The MATLAB Student package 1

MATLAB User Interface Variables in memory File manager Script editor Data structure in the selected.mat file Interactive command window MATLAB User Interface Provide interactive UI to implement machine learning Comment / uncomment code 2

Basic MATLAB Coding Go to: http://www.machinelearninghellix.site/ Download day one exercise use the interactive commands The result stored in ans Initiate variable and assign a value The equals sign (=) in MATLAB is the assignment operator Value goes from the right to the left = is NOT the equal sign Use the semicolon to suppress the output Recall the previous commands by the Up arrow key When you enter just a variable name, MATLAB returns the current value of that variable MATLAB does not use reference, so changing one variable does not affect another one Storing Data in Variables A MATLAB variable starts with a letter and contain only letters, numbers, and underscores(_) Use: clear <variable name> to clear the values in the variable Entering clear only will clean all variable Use clc to clears the Command Window MATLAB Built-in Functions & Constants MATLAB constants: pi, i We can use a script to define a set of MATLAB constants (MATLAB class on Day 2) MATLAB contains a wide variety of built in functions, such as abs (absolute value), trigonometry functions, and eig (calculate eigenvalues) MATLAB uses parentheses to pass inputs to functions, similar to standard mathematical notation. 3

Vectors and Matrices All MATLAB variables are arrays: each variable can contain multiple elements A single number, called a scalar, is actually a 1 by 1 array When you separate numbers by spaces (or commas), MATLAB combines the numbers into a row vector (1 by n) When you separate them by semicolons, MATLAB creates a column vector (n by 1) You can combine spaces and semicolons to create matrices Computation in a matrix Creating Evenly-Spaced Vectors use the : operator and specify only the start and end points The : operator uses a default spacing of 1. You can specify your own spacing Start : spacing : end If you know the number of elements you want in a vector, use the linspace function linspace(start,end,# of element) Use the transpose operator (ʹ) to convert a row vector into a column vector, or vise versa create column vectors in a single command Array Creation Functions MATLAB functions to create commonly used matrices matrices of random numbers: rand a matrix of all zeros: zeros A single number, called a scalar, is actually a 1-by-1 array When you separate numbers by spaces (or commas), MATLAB combines the numbers into a row vector (1-by-n) When you separate them by semicolons, MATLAB creates a column vector (n-by-1) You can combine spaces and semicolons to create matrices Computation in a matrix Save and load variables to a.mat file Save variables in the workspace to a MAT file use import tool 4

Indexing into and Modifying Arrays extract values from an array using row, column indexing Var = mat(row, col) use the MATLAB keyword end to refer the last element Var = mat(end,2) use arithmetic with the keyword end Var = mat(end 1,end 2) the 2nd last row and the 3rd last column To extract multiple elements, use the colon operator (:) specifies all the elements in that dimension. x = A(2,:) A row vector containing all of the elements from the second row of A The colon operator can refer to a range Use a single index to reference vector elements Changing Values in Arrays use the colon ( : ) character to extract entire columns of data The first row of a matrix: mat(1, end) The lost column of a matrix: mat(:, end) A single element with known index: mat(2, 3) 5

Array Operations MATLAB is designed to work naturally with arrays Addition You can add together any two arrays of the same size Do NOT add a row vector to a column vector multiply or divide all of the elements of an array by a scalar. Basic statistical functions in MATLAB can be applied to a vector to produce a single output MATLAB has functions that perform mathematical operations on an entire vector or array of values in a single command The asterisk (*) operator performs matrix multiplication dot product if you use * to multiply two equally sized vectors, since the inner dimensions do not agree, you will get an error message The.* operator performs elementwise multiplication Calling Functions size( ) apply to an array to produce a single output variable containing the array size max( ) the maximum value of a vector and its corresponding index value can be determined using the max function the first output from the max function is the maximum value of the input vector the second output is the index value if the input is a matrix, the max function will do column wise comparison min( ) mean( ) Obtaining Help Enter: doc fcnname to get information on any MATLAB function The MATLAB documentation contains a lot of good examples and information that can help you when working on your own problems Visit mathworks.com 6

plot(x axis, y axis) Plotting Data The plot function accepts an additional argument that allows you to specify the color, line style, and marker style using different symbols in single quotes. Use: doc plot for more information use the hold on command to hold the previous plot and add more plots on the same figure use the hold off command to return to the default behavior Use close all to close all figure windows When you plot a single vector by itself, MATLAB uses the vector values as % the y axis data and sets the x axis data to range from 1 to n The plot function accepts optional additional inputs consisting of a property name and an associated value. Annotating Plots Labels can be added to plots using plot annotation functions The input to these functions is a string Strings in MATLAB are enclosed in single quotes (ʹ) Use the PLOTS menu Logical Operations and Variables Relational operators such as >, <, ==, and ~= perform comparisons between two values. The outcome of a comparison for equality or inequality is either 1 (true) or 0 (false). Note that in MATLAB Not equal is: ~=, Do NOT use:!=, <> You can compare a vector or matrix to a single scalar value using relational operators The result is a logical array of the same size as the original array Corresponding elements of two arrays can be compared using relational operators. The two arrays must be the same size and the result is a logical array of the same size. 7

Combining Logical Conditions MATLAB contains logical operators which combine multiple logical conditions such as AND (&) OR ( ) The & operator returns true (1) if both elements are true, and false (0) otherwise The operator returns true (1) if either element is true Logical Indexing You can use a logical array as an array index, in which case MATLAB extracts the array elements where the index is true You can use logical indexing to reassign values in an array 8