How to Define, Add, and Subtract Matrices in MATLAB

Part 1 of 2:

Defining Matrices

  1. How to Define, Add, and Subtract Matrices in MATLAB Picture 1
    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.
  2. How to Define, Add, and Subtract Matrices in MATLAB Picture 2
    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".
  3. How to Define, Add, and Subtract Matrices in MATLAB Picture 3
    Type an "=" followed by a left bracket, "[". Typing, "A=[" is the same as, "A = [". Spacing in between these characters is acceptable.
  4. How to Define, Add, and Subtract Matrices in MATLAB Picture 4
    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, "]".
  5. How to Define, Add, and Subtract Matrices in MATLAB Picture 5
    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.
  6. How to Define, Add, and Subtract Matrices in MATLAB Picture 6
    Review your work. If you are content with the way your matrix is defined, you may now perform functions with it.
    1. 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

  1. How to Define, Add, and Subtract Matrices in MATLAB Picture 7
    Define the desired matrices, as explained above. In this example, we will use two matrices. These have identifiers "A" and "B".
  2. How to Define, Add, and Subtract Matrices in MATLAB Picture 8
    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.
  3. How to Define, Add, and Subtract Matrices in MATLAB Picture 9
    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.
  4. How to Define, Add, and Subtract Matrices in MATLAB Picture 10
    Press Enter.
  5. How to Define, Add, and Subtract Matrices in MATLAB Picture 11
    Check the answer. You should see the desired result printed to the screen, and the new variable "ans" in the "Workspace" window.
  6. How to Define, Add, and Subtract Matrices in MATLAB Picture 12
    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

May be interested

  • Class (Class) in C #Class (Class) in C #
    when you define a class in c #, you define a blueprint for a data type. this does not really define any data, but it defines the meaning of that class name. that is, what an object of that class consists of, what activities can be performed on that object.
  • How to use subtraction in ExcelHow to use subtraction in Excel
    subtraction in excel is a basic calculation, which is used a lot in excel calculation exercises.
  • How to Use MatLab to Solve Matrix Equations and Perform Statistical AnalysisHow to Use MatLab to Solve Matrix Equations and Perform Statistical Analysis
    this 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 calculate time in Excel: Add and subtract timeHow to calculate time in Excel: Add and subtract time
    excel can calculate the amount of time by adding / subtracting method to give you the result of the amount of time in minutes, hours, days, and months. the following software tips will guide you the most basic formulas. the problem is that you have time to complete two steps of work, and you want to know how many hours and minutes it will take to complete the job.
  • EDATE function - Add and subtract months to a specified date in ExcelEDATE function - Add and subtract months to a specified date in Excel
    edate function: the function that adds (subtracts) months on a specified date. use this function to calculate the due date that matches the release date in the month. syntax: edate (start_date, months)
  • Tried to define 'rootkit'Tried to define 'rootkit'
    after being severely criticized for the rootkit scandal inside norton systemworks, symantec urgently called on the entire security industry to soon build a standard concept to define what 'rootkits' are.
  • Union in CUnion in C
    a union is a special data in c language that allows you to reserve different data types in the same memory. you can define union with a lot of parameters, but only one component contains values ​​at a time. union provides an effective way to use a device for multiple purposes.
  • Keyword typedef in CKeyword typedef in C
    the c program language provides a typedef keyword, which you can use to provide the type for a new name. here is an example to define a byte entry for 1-byte numbers (like unsigned char).
  • Preprocessor directive in C #Preprocessor directive in C #
    preprocessor directive directives provide instructions to the compiler to preprocess the information before the actual compilation process begins. all preprocessor directives in c # start with #, and only white-space characters can appear before a preprocessor directive in a line. preprocessor directives in c # are not commands, so they do not end with a semicolon (;).
  • Python functions are user definedPython functions are user defined
    besides the built-in python functions, you can also define python functions yourself, these functions are called user-defined functions (python). what are the benefits of using these self-defined functions, the best way to define functions in python, we'll learn in this python lesson.