Multimedia Technology in MATLAB By: Mustafa N. Jaafar Lecture1: MATLAB Introduction
INSTALL MATLAB R2021A 1. To install MATLAB R2021a, insert the MATLAB flash drive or extract the downloaded .zip file, go into the Matlab for Windows folder, then double-click on setup.exe.
STEP 2: CHOOSE TO INSTALL WITHOUT USING THE INTERNET
STEP 3: REVIEW THE LICENSE AGREEMENT
STEP 4: SPECIFY THE FILE INSTALLATION KEY
LEAVE THE DEFAULT INSTALLATION FOLDER LOCATION. CLICK NEXT.
LEAVE THE DEFAULT PRODUCT SELECTION. CLICK NEXT.
BEGIN INSTALL
INSTALLATION COMPLETE WINDOW, CLICK FINISH.
THE GRAPHICAL INTERFACE TO THE MATLAB WORKSPACE
USING MATLAB AS A CALCULATOR • >> 1+2*3 ans = 7 • >> x = 1+2*3 x = 7 • >> 4*x ans = 28.000 • >> (1+2)*3 ans = 9 • >> 1/(2+3^2)+4/5*6/7 ans = 0.7766 • >> 1/2+3^2+4/5*6/7 ans = 10.1857
OVERWRITING VARIABLE • >> t = 5; • >> t = t+1 • t = 6 ERROR MESSAGES • >> x = 10; • >> 5x • ??? 5x • | • Error: Unexpected MATLAB expression.
MANAGING THE WORKSPACE • >> clear The command clear or clear all removes all variables from the workspace. This frees up system memory. In order to display a list of the variables currently in the memory, type GETTING HELP • >> help sqrt • In the current version the doc function opens the on-line version of the help manual. This is very helpful for more complex commands.
MATHEMATICAL FUNCTIONS
VECTOR GENERATION • For example, to enter a row vector, v, type >> v = [1 4 7 10 13] v = 1 4 7 10 13 • Column vectors are created in a similar way, however, semicolon (;) must separate the components of a column vector, >> w = [1;4;7;10;13] w = 1 4 7 10 13
VECTOR GENERATION • transpose operator. The transpose operation is denoted by an apostrophe or a single quote (’). >> w = v ’ w = 1 4 7 10 13 • o access blocks of elements, we use MATLAB’s colon notation (:). For example, to access the first three elements of v, we write >> v(1:3) ans = 1 4 7
ENTERING A MATRIX • A matrix is an array of numbers. To type a matrix into MATLAB you must • begin with a square bracket, [ • separate elements in a row with spaces or commas (,) • use a semicolon (;) to separate rows • end the matrix with another square bracket, ]. 20 • We can then view a particular element in a matrix by specifying its location. We write, >> A(2,1) • ans = 4
DELETING ROW OR COLUMN • To delete a row or column of a matrix, use the empty vector operator, [ ]. >> A(3,:) = [] A = 1 2 3 4 5 6 DIMENSION • To determine the dimensions of a matrix or vector, use the command size. For example, >> size(A) ans = 3 3
ARRAY OPERATIONS • As we mentioned earlier, MATLAB allows arithmetic operations: +, −, ∗, and ˆ to be carried out on matrices.Thus, A+B or B+A  is valid if A and B are of the same size A*B  is valid if A’s number of column equals B’s number of rows A^2  is valid if A is square and equals A*A α*A or A*α  multiplies each element of A by α .*  Element-by-element multiplication ./  Element-by-element division .^  Element-by-element exponentiation
SUMMARY OF MATRIX AND ARRAY OPERATIONS
INTRODUCTION TO PROGRAMMING IN MATLAB • Therefore, a different way of executing repeatedly commands with MATLAB is: 1. to create a file with a list of commands, 2. 2. save the file, and 3. 3. run the file. • If needed, corrections or changes can be made to the commands in the file. The files that are used for this purpose are called script files or scripts for short. This section covers the following topics: • M-File Scripts • M-File Functions
CONTROL FLOW • The ‘‘if...end’’ structure • MATLAB supports the variants of “if” construct. • if ... End • if ... else ... end • if ... elseif ... else ... end
THE ‘‘FOR...END’’ LOOP • n the for ... end loop, the execution of a command is repeated at a fixed and predetermined number of times. The syntax is for variable = expression statements end • Example for ii=1:5 x=ii*ii end
THE ‘‘WHILE...END’’ • loop This loop is used when the number of passes is not specified. The looping continues until a stated condition is satisfied. The while loop has the form: while expression statements end • The statements are executed as long as expression is true. x = 1 while x <= 10 x = 3*x end
REFERENCE • https://www.mathworks.com/?s_tid=gn_logo • Houcque, David. "Introduction to Matlab for engineering students." Northwestern University 1 (2005).

Introduction to programming in MATLAB

  • 1.
    Multimedia Technology in MATLAB By: MustafaN. Jaafar Lecture1: MATLAB Introduction
  • 2.
    INSTALL MATLAB R2021A 1.To install MATLAB R2021a, insert the MATLAB flash drive or extract the downloaded .zip file, go into the Matlab for Windows folder, then double-click on setup.exe.
  • 3.
    STEP 2: CHOOSETO INSTALL WITHOUT USING THE INTERNET
  • 4.
    STEP 3: REVIEWTHE LICENSE AGREEMENT
  • 5.
    STEP 4: SPECIFYTHE FILE INSTALLATION KEY
  • 6.
    LEAVE THE DEFAULTINSTALLATION FOLDER LOCATION. CLICK NEXT.
  • 7.
    LEAVE THE DEFAULTPRODUCT SELECTION. CLICK NEXT.
  • 9.
  • 10.
  • 11.
    THE GRAPHICAL INTERFACETO THE MATLAB WORKSPACE
  • 12.
    USING MATLAB ASA CALCULATOR • >> 1+2*3 ans = 7 • >> x = 1+2*3 x = 7 • >> 4*x ans = 28.000 • >> (1+2)*3 ans = 9 • >> 1/(2+3^2)+4/5*6/7 ans = 0.7766 • >> 1/2+3^2+4/5*6/7 ans = 10.1857
  • 13.
    OVERWRITING VARIABLE • >>t = 5; • >> t = t+1 • t = 6 ERROR MESSAGES • >> x = 10; • >> 5x • ??? 5x • | • Error: Unexpected MATLAB expression.
  • 14.
    MANAGING THE WORKSPACE •>> clear The command clear or clear all removes all variables from the workspace. This frees up system memory. In order to display a list of the variables currently in the memory, type GETTING HELP • >> help sqrt • In the current version the doc function opens the on-line version of the help manual. This is very helpful for more complex commands.
  • 15.
  • 16.
    VECTOR GENERATION • Forexample, to enter a row vector, v, type >> v = [1 4 7 10 13] v = 1 4 7 10 13 • Column vectors are created in a similar way, however, semicolon (;) must separate the components of a column vector, >> w = [1;4;7;10;13] w = 1 4 7 10 13
  • 17.
    VECTOR GENERATION • transposeoperator. The transpose operation is denoted by an apostrophe or a single quote (’). >> w = v ’ w = 1 4 7 10 13 • o access blocks of elements, we use MATLAB’s colon notation (:). For example, to access the first three elements of v, we write >> v(1:3) ans = 1 4 7
  • 18.
    ENTERING A MATRIX •A matrix is an array of numbers. To type a matrix into MATLAB you must • begin with a square bracket, [ • separate elements in a row with spaces or commas (,) • use a semicolon (;) to separate rows • end the matrix with another square bracket, ]. 20 • We can then view a particular element in a matrix by specifying its location. We write, >> A(2,1) • ans = 4
  • 19.
    DELETING ROW ORCOLUMN • To delete a row or column of a matrix, use the empty vector operator, [ ]. >> A(3,:) = [] A = 1 2 3 4 5 6 DIMENSION • To determine the dimensions of a matrix or vector, use the command size. For example, >> size(A) ans = 3 3
  • 20.
    ARRAY OPERATIONS • Aswe mentioned earlier, MATLAB allows arithmetic operations: +, −, ∗, and ˆ to be carried out on matrices.Thus, A+B or B+A  is valid if A and B are of the same size A*B  is valid if A’s number of column equals B’s number of rows A^2  is valid if A is square and equals A*A α*A or A*α  multiplies each element of A by α .*  Element-by-element multiplication ./  Element-by-element division .^  Element-by-element exponentiation
  • 21.
    SUMMARY OF MATRIXAND ARRAY OPERATIONS
  • 22.
    INTRODUCTION TO PROGRAMMINGIN MATLAB • Therefore, a different way of executing repeatedly commands with MATLAB is: 1. to create a file with a list of commands, 2. 2. save the file, and 3. 3. run the file. • If needed, corrections or changes can be made to the commands in the file. The files that are used for this purpose are called script files or scripts for short. This section covers the following topics: • M-File Scripts • M-File Functions
  • 23.
    CONTROL FLOW • The‘‘if...end’’ structure • MATLAB supports the variants of “if” construct. • if ... End • if ... else ... end • if ... elseif ... else ... end
  • 24.
    THE ‘‘FOR...END’’ LOOP •n the for ... end loop, the execution of a command is repeated at a fixed and predetermined number of times. The syntax is for variable = expression statements end • Example for ii=1:5 x=ii*ii end
  • 25.
    THE ‘‘WHILE...END’’ • loopThis loop is used when the number of passes is not specified. The looping continues until a stated condition is satisfied. The while loop has the form: while expression statements end • The statements are executed as long as expression is true. x = 1 while x <= 10 x = 3*x end
  • 26.
    REFERENCE • https://www.mathworks.com/?s_tid=gn_logo • Houcque,David. "Introduction to Matlab for engineering students." Northwestern University 1 (2005).