How to Define, Add, and Subtract Matrices in MATLAB
Part 1 of 2:
Defining Matrices
- Launch MATLAB and wait until you get a screen similar to the one shown. Depending on your edition, you may get a message stating "Student License --". This is not an error and should not hinder functionality.
- Type a letter, word, or otherwise simple identifier for your new matrix in the command window. Note that the identifier may not contain spaces and that all identifiers are case sensitive. Therefore, "A" is not the same as "a". In this example, we will define our matrix as "A".
- Type an "=" followed by a left bracket, "[". Typing, "A=[" is the same as, "A = [". Spacing in between these characters is acceptable.
- Begin adding values to your matrix. These values may be numbers or other predefined variables. In this case, we will stick to just whole numbers. Columns in a matrix are separated with spaces, i.e. pressing the "Space Bar" after typing a number or variable. Rows are separated with semicolons. Close the matrix with a right bracket, "]".
- Click ↵ Enter to officially define your matrix. The matrix you have just defined will print itself in the "Command Window". It will also be visible in the "Workspace" window.
- Review your work. If you are content with the way your matrix is defined, you may now perform functions with it.
- If your matrix does not appear as desired, you may easily re-define it. Perform the exact same steps as above. As long as you choose the exact same identifier, the old matrix will be updated with the new data. Note the change in the "Workspace" window.
Part 2 of 2:
Adding or Subtracting Matrices
- Define the desired matrices, as explained above. In this example, we will use two matrices. These have identifiers "A" and "B".
- Realize that, in order to be added or subtracted, two matrices need to be the same length and width. If they are not, you will get an error message.
- Type the identifier of the first matrix followed by a plus sign, "+", if you want to do addition, or a "-" sign if you want to do subtraction. Type the identifier of the second matrix to be added. Continue this process for all desired matrices, being sure to separate the identifiers with plus signs.
- Press ↵ Enter.
- Check the answer. You should see the desired result printed to the screen, and the new variable "ans" in the "Workspace" window.
- Perform more calculations. You may now take matrix "ans" and perform many more calculations with it. Treat "ans" the same way you would any other matrix identifier. All of the same addition and subtraction rules apply.
5 ★ | 1 Vote
You should read it
- Matrix Ransomware is back under the distribution of RIG Exploit Kit
- Introduction to 2D Array - 2-dimensional array in JavaScript
- Matrix in Python
- Matrix functions in Excel
- MINVERSE function - The function returns the inverse matrix of a given matrix in Excel
- How to find the SID (Security Identifier) for a user account in Windows
- How to Use MatLab to Solve Matrix Equations and Perform Statistical Analysis
- The Matrix 4, in turn, announced a production suspension because of Covid-19, Keanu Reeves' Day in 2021 could be canceled.
May be interested
- How to Make 3D Plots Using MATLABwhether it's for research, a school assignment, or a work presentation, 3-d plots are great for visualizing what a complicated set of data looks like. with the help of matlab (matrix laboratory), you'll be able to create stunning 3-d...
- How to Use MatLab to Solve Matrix Equations and Perform Statistical Analysisthis instruction set explains how to solve a matrix equation and perform statistical analysis on a matrix in matlab. *the matrix equations will be in the form ax=b. *the statistical analysis will find the total number of data points as...
- How to Download MATLAB on a Macdo you having trouble downloading matlab to your mac? matlab is a programming software that most undergraduate engineering students will download and use during their college career. this article will explain step-by-step how to download...
- How to Create a Matrix, Vector, and Cell Array in MATLABthis article covers how to create matrices, vectors, and cell arrays with the programming software matlab. since matlab is a program offering endless possibilities, being able to understand the basics will lead to the ability to write more...
- How to Import, Graph, and Label Excel Data in MATLABwhether you are an experienced matlab user or a novice, you may not be fully aware of matlab's graphing abilities. matlab allows you to easily customize, label, and analyze graphs, giving you more freedom than the traditional excel graph....
- How to Think Like a Programmerthinking like a programmer primarily means being persistent and meticulous in your attention to details. jump into programming challenges feet-first, but review your work carefully as you proceed to ensure you don't end up with any bugs in...