Skip to main content

Posts

Showing posts with the label Matrix

Matrix calculation with MATLAB Programming

First, let's create a simple vector with 9 elements called a . a = [1 2 3 4 6 4 3 4 5] a = 1 2 3 4 6 4 3 4 5 Now let's add 2 to each element of our vector, a , and store the result in a new vector. Notice how MATLAB requires no special handling of vector or matrix math. b = a + 2 b = 3 4 5 6 8 6 5 6 7 Creating graphs in MATLAB is as easy as one command. Let's plot the result of our vector addition with grid lines. plot(b) grid on MATLAB can make other graph types as well, with axis labels. bar(b) xlabel( 'Sample #' ) ylabel( 'Pounds' ) MATLAB can use symbols in plots as well. Here is an example using stars to mark the points. MATLAB offers a variety of other symbols and line types. plot(b, '*' ) axis([0 10 0 10]) One area in which MATLAB excels is matrix computation. Creating a matrix is as easy as making a vector, using semicolons (;) to separate the rows of a matrix. A = [1 2