Matrices in Matlab

Good Essays
Section 2.2

Matrices in Matlab 75

2.2 Matrices in Matlab
You can think of a matrix as being made up of 1 or more row vectors of equal length. Equivalently, you can think of a matrix of being made up of 1 or more column vectors of equal length. Consider, for example, the matrix   1 2 3 0 A =  5 −1 0 0  . 3 −2 5 0 One could say that the matrix A is made up of 3 rows of length 4. Equivalently, one could say that matrix A is made up of 4 columns of length 3. In either model, we have 3 rows and 4 columns. We will say that the dimensions of the matrix are 3-by-4, sometimes written 3 × 4. We already know how to enter a matrix in Matlab: delimit each item in a row with a space or comma, and start a new row by ending a row with a semicolon. >> A=[1 2 3 0;5 -1 0 0;3 -2 5 0] A = 1 2 3 0 5 -1 0 0 3 -2 5 0 We can use Matlab’s size command to determine the dimensions of any matrix. >> size(A) ans = 3 4 That’s 3 rows and 4 columns!

Indexing
Indexing matrices in Matlab is similar to the indexing we saw with vectors. The difference is that there is another dimension 2. To access the element in row 2 column 3 of matrix A, enter this command.

1 2

Copyrighted material. See: http://msenux.redwoods.edu/Math4Textbook/ We’ll see later that we can have more than two dimensions.

76 Chapter 2

Vectors and Matrices in Matlab

>> A(2,3) ans = 0 This is indeed the element in row 2, column 3 of matrix A. You can access an entire row with Matlab’s colon operator. The command A(2,:) essentially means “row 2 every column” of matrix A. >> A(2,:) ans = 5 -1

0

0

Note that this is the second row of matrix A. Similarly, you can access any column of matrix A. The notation A(:,2) is pronounced “every row column 2” of matrix A. >> A(:,2) ans = 2 -1 -2 Note that this is the second column of matrix A. You can also extract a submatrix from the matrix A with indexing. Suppose, for example, that you would like to extract a submatrix using rows 1 and 3 and columns 2 and 4. >>

You May Also Find These Documents Helpful

  • Good Essays

    Matlab

    • 18263 Words
    • 74 Pages

    An Introduction to Matlab Version 2.3 David F. Griffiths Department of Mathematics The University Dundee DD1 4HN With additional material by Ulf Carlsson Department of Vehicle Engineering KTH, Stockholm, Sweden Copyright c 1996 by David F. Griffiths. Amended October, 1997, August 2001, September 2005. This introduction may be distributed provided that it is not be altered in any way and that its source is properly and completely specified. Contents 1 MATLAB 2 Starting Up 2.1 Windows Systems…

    • 18263 Words
    • 74 Pages
    Good Essays
  • Good Essays

    MATLAB

    • 1938 Words
    • 20 Pages

    components – MATLAB – Revision, Numerical Integration, Root Finding • Dr Mike Clee • Lectures – Weeks 2-4, Labs – Weeks 3-5 • 50% 1 assignment – CAD – Solidworks • Dr Chengyuan Wang • Lectures Weeks 5-6, Labs – Weeks 6-12 • 50% – 1 assignments Semester 1, 2014-2015 General Information • MATLAB lab slots – There will be demonstrators in each lab to help with MATLAB worksheets – Each student has the opportunity to complete the assignment during the lab sessions – Remember - MATLAB labs will be…

    • 1938 Words
    • 20 Pages
    Good Essays
  • Better Essays

    Matlab

    • 4159 Words
    • 17 Pages

    MATLAB BEGINNER’S GUIDE 0 About MATLAB MATLAB is an interactive software which has been used recently in various areas of engineering and scientific applications. It is not a computer language in the normal sense but it does most of the work of a computer language. Writing a computer code is not a straightforward job, typically boring and time consuming for beginners. One attractive aspect of MATLAB is that it is relatively easy to learn. It is written on an intuitive basis and it does not…

    • 4159 Words
    • 17 Pages
    Better Essays
  • Good Essays

    Matrices

    • 546 Words
    • 4 Pages

    1. Use the following matrices to perform the indicated matrix operations, if possible. 2. Use the following matrices to perform the indicated matrix operations, if possible. 3. Use the following matrices to perform the indicated matrix operations, if possible. 4. Use the matrices to find DE, if possible. 5. Use matrix A to find , if possible. 6. Suppose the weights (in grams) and lengths (in centimeters) of three groups of laboratory animals…

    • 546 Words
    • 4 Pages
    Good Essays
  • Powerful Essays

    Matlab Manual

    • 11755 Words
    • 48 Pages

    AP Induction Week Course Introduction to Engineering Computation Laboratory Manual MATLAB programming Department of Engineering Science MATLAB Laboratory Manual Contents Laboratory 1: An introduction to MATLAB ............................................................................................ 2 Laboratory 2: Debugging, Functions and Problem Solving ............................................................22 Laboratory 3: Logical Operators, Conditional Statements and Loops…

    • 11755 Words
    • 48 Pages
    Powerful Essays
  • Powerful Essays

    Matlab Study

    • 3452 Words
    • 14 Pages

    Introduction to Programming in MATLAB 6.094 Lecture 1: Variables, Scripts, and Operations Danilo Šćepanović IAP 2010 Course Layout • Lectures 1: 2: 3: 4: 5: Variables, Scripts and Operations Visualization and Programming Solving Equations, Fitting Images, Animations, Advanced Methods Optional: Symbolic Math, Simulink Course Layout • Problem Sets / Office Hours One per day, should take about 3 hours to do Submit doc or pdf (include code, figures) No set office hours but available…

    • 3452 Words
    • 14 Pages
    Powerful Essays
  • Powerful Essays

    Matlab

    • 2459 Words
    • 13 Pages

    3217 DECEMBER 9, 2008 WILLIAM E. BRUNS SHARON M. BRUNS SUSAN HARMELING Merrimack Tractors and Mowers, Inc.: LIFO or FIFO? Ricardo “Rick” Martino, president and chief operating officer of Merrimack Tractors and Mowers, Inc., of Nashua, New Hampshire, felt that his job had grown much more complicated during 2007 and 2008. Merrimack was a major regional manufacturer and seller of large commercial grass mowers based on a design developed by his grandfather in the years after World War II…

    • 2459 Words
    • 13 Pages
    Powerful Essays
  • Powerful Essays

    Mp4 Matlab

    • 2235 Words
    • 9 Pages

    College of Engineering ELECTRONICS AND COMMUNICATIONS ENGINEERING NDC Compound, *Anonas* St. Sta. Mesa, Manila {draw:line} Research Work with Defense Submitted By: Group 3 - Alpha Signal Rho BSECE IV-1 Leader : SANTOS, Ralph Rhyan G. Members: BELANO, Gracielle D. ESPINOSA, Joey Q. HERNANDEZ, Jan Roldan B. MATIC, Millicent G. RIVO, Sarah Ezekiel M. VILLENA, Kane Dave R Engr. Gerhard P. Tan Instructor Introduction It is known that our fast-paced…

    • 2235 Words
    • 9 Pages
    Powerful Essays
  • Good Essays

    INTRODUCTION TO MATLAB

    • 832 Words
    • 8 Pages

    INTRODUCTION TO MATLAB © Dr. James S. Kang, Professor, ECE Department, Cal Poly Pomona Opening MATLAB Start → Programs → MATLAB → R2010a → MATLAB R2010a or double click on icon ( ). Slightly different for different versions and operating systems. The MATLAB window opens up as shown below. Depending on Desktop options, the window looks different. Set the Current Folder on top of the screen. Working on Command Window We are demonstrating the use of Command Window by solving HW Problem 1.9 1.9 The…

    • 832 Words
    • 8 Pages
    Good Essays
  • Good Essays

    Matlab Gatool

    • 482 Words
    • 2 Pages

    Using Matlab to Execute a Genetic Algorithm Optimization of Two Variable Function The function to be optimized is given by: [pic] The maximum value of this two variable function is desired, however Matlab’s gatool finds the minimum of fitness functions and so as in the previous example the function must be altered as follows: [pic] Now we must enter this function, as before, into a Matlab function file. Start Matlab and change the working directory to your Knowledge…

    • 482 Words
    • 2 Pages
    Good Essays