MATLAB Practice 1 Introducing MATLAB Lecture Notes on Video Search & Mining, Spring 2012 Presented by Jun Hee Yoo Biointelligence Laboratory School of.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
General Computer Science for Engineers CISC 106 Lecture 08 Dr. John Cavazos Computer and Information Sciences 2/27/2009.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Introduction to MATLAB
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.
Lecture 13: M/O/F/ for Engineering Applications - Part 1 BJ Furman 26NOV2012.
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.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
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.
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
INTRODUCTION TO MATLAB LAB# 01
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
CMPS 1371 Introduction to Computing for Engineers MatLab.
MATLAB Practice 2 Introducing MATLAB Lecture Notes on Video Search & Mining, Spring 2012 Presented by Jun Hee Yoo Biointelligence Laboratory School of.
Matlab The language of Technical computing Mr. D. Suresh Assistant Professor, Dept. of CSE, PSNA CET, Dindigul.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
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.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Lecture 3: M/O/F/ for Engineering Applications B Burlingame 16September2015.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
A simple classification problem Extract attributes Pattern Pattern recognition decision x C1 C2.
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.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Digital Image Processing Introduction to M-function Programming.
Introduction to Matlab
Introduction to Matlab Electromagnetic Theory LAB by Engr. Mian Shahzad Iqbal.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
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 Patrice Koehl Department of Biological Sciences National University of Singapore
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
MATLAB Constants, Variables & Expression Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Lecture 12: M/O/F/ for Engineering Applications B Burlingame 27 April 2016.
전자장 1 실험 - Matlab 사용법 - Photonic Systems Laboratory School of EE, Seoul National University Photonic Systems Lab School of EECS, S.N.U.
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.
Intro To MATLAB CS Fall 2013 Zach Welch. Overview ●Basics ●MATLAB data structures ●Operations ●Useful functions ●Image Processing and other useful.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
Matlab Programming for Engineers
L – Modeling and Simulating Social Systems with MATLAB
MATLAB Basics Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
Introduction To Matlab Class 1
L – Modelling and Simulating Social Systems with MATLAB
StatLab Matlab Workshop
CS100J 26 April. Matlab Use help button!!! Variables, values, types
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
INTRODUCTION TO MATLAB
Experiment No. (1) - an introduction to MATLAB
Announcements P3 due today
Presentation transcript:

MATLAB Practice 1 Introducing MATLAB Lecture Notes on Video Search & Mining, Spring 2012 Presented by Jun Hee Yoo Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy

Contents What is the MATLAB? Pros & cons. Environment Basics Variables Operators Editor Loop, Branch Practice I To be Beginner(maybe next time) Functions Error Handling Useful Tips © 2012, SNU CSE Biointelligence Lab.,

What is MATLAB? MATLAB Practice 1 - Introducing MATLAB © 2012, SNU CSE Biointelligence Lab.,

What is MATLAB? Short for MATrix LABoratory Pros Ease to Use A lots of built-in useful functions. Script language Platform Independence Can use with C/C++ and JAVA Cons Slower than native programs It’s commercial software GNU Octave is free!!! © 2012, SNU CSE Biointelligence Lab.,

Environment Base window © 2012, SNU CSE Biointelligence Lab., Browser Workspace Command Window Command History Detail (Preview) Start Button

Environment Figure window © 2012, SNU CSE Biointelligence Lab., Plot Tool logo.m

Environment Text Editor Window © 2012, SNU CSE Biointelligence Lab.,

Basics MATLAB Practice 1 - Introducing MATLAB © 2012, SNU CSE Biointelligence Lab.,

Basics Variables Basic classes(type) Integer( int8, int16, int32, int64, uint8, uint16, uint32, uint64 ) Real Single Doublex = 10 Complexx = i Character x = ‘a’ ( to assign string, ‘abc’ or [‘a’ ‘b’ ‘c’] ) And Etc. (cell, struct, object, boolean) What is different between ‘x = 10’ and ‘x = 10;’? © 2012, SNU CSE Biointelligence Lab., variable = expression (Double is default type)

Basics Assign matrix 1 Dim 2 Dim 3 Dim © 2012, SNU CSE Biointelligence Lab., x1 = [1 2 3]; x2 = [1, 2, 3]; x3 = [1;2;3]; x = [[1 2 3]; [4 5 6]; [7 8 9]]; or x = [1 2 3; 4 5 6; 7 8 9]; x = [[1 2 3];or x = [ 1 2 3; [4 5 6]; 4 5 6; [7 8 9]]; 7 8 9]; x = [[[1 2 3]; [4 5 6]; [7 8 9]];]; ?? x = [1 2 3; 4 5 6; 7 8 9]; x( :, :, 2) = [ ; ; ];

Basics Assign matrix DIY - Create Dim 4 and Dim 5 matrix. © 2012, SNU CSE Biointelligence Lab., x = [1 2 3; 4 5 6; 7 8 9];- 2D x( :, :, 2) = x( :, : );- 3D x( :, :, :, 2) = x( :, :, :);- 4D x( :, :, :, :, 2) = x( :, :, :, : );- 5D

Basics © 2012, SNU CSE Biointelligence Lab.,

Basics Usage of ‘:’ in subscript DIY >> A = [ 1 2 3; 4 5 6; ]; >> A( :, 2 ); >> A( 1, : ); >> B = A; >> B( :, :, 2 ) = 2*A; >> B( 1, 1, : ); >> B( :, :, 3) = 3*A; © 2012, SNU CSE Biointelligence Lab.,

Basics Usage of ‘:’ in subscript DIY © 2012, SNU CSE Biointelligence Lab., B = Try other cases!

Basics Dimension and index © 2012, SNU CSE Biointelligence Lab., 2D 3D

Basics Basic operators © 2012, SNU CSE Biointelligence Lab., OperationAlgebraic FormMATLAB form Additiona + b Subtractiona – b Multiplicationa * b Divisiona / b Exponentiationa ^ b

Basics Basic operators © 2012, SNU CSE Biointelligence Lab., OperationMATLAB formComments Matrix AdditionA + BA and B must be same dimension. Matrix SubtractionA – BA and B must be same dimension. Matrix MultiplicationA * Bcols of A and rows of B must be same. Matrix Right DivisionA / B? Matrix Left DivisionA \ B?

Basics Basic operators DIY >> A = [ ]; >> B = [ ]; >> A / B ans = ? © 2012, SNU CSE Biointelligence Lab., DIY >> A = magic(3); >> B = [ 1; 2; 3 ]; >> x = A \ B >> A*x ans = ? In MATLAB, if matrix is not square shape or doesn’t have inverse matrix, it uses ‘pseudo inverse matrix’.

Basics dot operator DIY >> A = pascal(3); >> B = A ^ 2;% this is same as B = A * A; >> C = A.^ 2; B and C are same? DIY >> A = [ ]; >> B = [ ]; >> A.* B% in this case, A and B must be same % shape © 2012, SNU CSE Biointelligence Lab.,

Basics dot operator A.* B Element-by-element multiplication of a and b. Both arrays must be the same shape, or one of them must be a scalar A./ B Element-by-element right division of a and b : a(i,j) / b(i,j). Both arrays must be the same shape, or one of them must be a scalar. A.\ B Same constraints as A./ B. © 2012, SNU CSE Biointelligence Lab.,

Basics colon operator DIY A = 1:10; B = 1:2:10; C = 5:0.5:7; D = 0:-1:5; A = [ ] B = [ ] C = [ ] D = [ ] © 2012, SNU CSE Biointelligence Lab.,

Basics Transpose operator DIY >> A = [ ]; >> B = A’ >> C = A’’ © 2012, SNU CSE Biointelligence Lab.,

Basics Relational & Logical Operators © 2012, SNU CSE Biointelligence Lab., OperatorOperationOperatorOperation ==Equal to&AND ~=Not Equal to|OR >Greater than~NOT >=Greater than or equal to <Less than <=Less than or equal to

Basics Relational & Logical Operators DIY >> x = [ 0 : 3 : 15 ]; >> y = [ 0 : 2 : 10 ]; >> x > y >> x == y >> x < y >> x ~= y >> u = randint(1, 6); >> v = randint(1, 6); >> u & v >> u | v >> ~u © 2012, SNU CSE Biointelligence Lab.,

Basics Tips clear variable_name remove variable from workspace ‘clear all’ will remove all variables in workspace clc clear command window © 2012, SNU CSE Biointelligence Lab.,

Basics *.m file Using command windows is inefficient when process long code. So, MATLAB supports a script editor © 2012, SNU CSE Biointelligence Lab., Click or CTRL+N

Basics Editor 1. new document 2. execute current m-file Do not use any white space character in file name. Please, write your file name in English. Also, the path should be written in English. © 2012, SNU CSE Biointelligence Lab.,

Basics Loop ‘for’ statement for iteration = initial_value : step : final_value end DIY ( write in the script editor ) for i = 1:10 disp(i); end *while is loop statements too. © 2012, SNU CSE Biointelligence Lab.,

Basics Branch ‘if’ statement if relation or logical expression statements; elseif relation or logical expression% optional statements; else % optional statements; end * keyword ‘swicth’ is branch statement too. © 2012, SNU CSE Biointelligence Lab.,

Basics Loop and Branch statements can be nested Example for i = 1:2:10 if i <= 5 if i == 1 disp(i); end elseif i > 5 && i < 10 for j = i:10 disp(j); end else end © 2012, SNU CSE Biointelligence Lab.,

Practice I MATLAB Practice 1 - Introducing MATLAB © 2012, SNU CSE Biointelligence Lab.,

Practice I Function call MATLAB has many powerful Built-in functions. DIY >> A = rand(1); >> B = ceil(A); To see the explanation of functions >> help function_name DIY >> help rand © 2012, SNU CSE Biointelligence Lab.,

Practice I Automated Lottery Program Generate 6 number between 1~45 for n times (n = 100) Generated numbers must not contain same number. You can use… ceil() rand() sum() Google!! You can not use… Any other random functions. (such as randperm()) © 2012, SNU CSE Biointelligence Lab.,