Matlab-Matrix Tutorial
Selected Reading
- Matlab Matrix - Discussion
- Matlab Matrix - Useful Resources
- Matlab Matrix - Quick Guide
- Matlab-Matrix - Deletion Row & Coloumn
- Matlab-Matrix - Transpose
- Matlab-Matrix - Rank
- Matlab-Matrix - Trace
- Matlab-Matrix - Inverse
- Matlab-Matrix - Matrix Determinant
- Matlab-Matrix - Subtraction
- Matlab-Matrix - Addition
- Matlab-Matrix - Multiplication
- Matlab-Matrix - Working with Matrices
- Matlab-Matrix - Create Matrix
- Matlab-Matrix - Environment Setup
- Matlab-Matrix - Introduction
- Matlab-Matrix - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Matlab-Matrix - Subtraction
Matlab-Matrix - Subtraction
To subtract two matrices, both the operand matrices must have the same number of rows and columns.
Example
Here is an example −
a = [ 1 2 3 ; 4 5 6; 7 8 9]; b = [ 7 5 6 ; 2 0 8; 5 7 1]; c = a - b
Output
On execution in MATLAB the result is as follows −
>> a = [ 1 2 3 ; 4 5 6; 7 8 9]; b = [ 7 5 6 ; 2 0 8; 5 7 1]; c = a - b c = -6 -3 -3 2 5 -2 2 1 8 >>
The minus() Function
You can also make use of the minus() built-in function to subtract two matrices.
Example
Consider the following example for use of minus() function for subtraction of two matrices −
a = [ 1 2 3 ; 4 5 6; 7 8 9]; b = [ 7 5 6 ; 2 0 8; 5 7 1]; c = minus(a , b)
Output
You will get the following result −
>> a = [ 1 2 3 ; 4 5 6; 7 8 9]; b = [ 7 5 6 ; 2 0 8; 5 7 1]; c = minus(a , b) c = -6 -3 -3 2 5 -2 2 1 8 >>Advertisements