Tutorial Video
Element by Element Subtraction
Array subtraction works in an identical manner to element by element subtraction therefore it does not matter if we use -
or .-
.
Subtraction of Scalars
The items we illustrated are consumables. Taking the case of scalars, in this case only looking at pens, assuming we have 8 pens and use 6 of them up writing then after we put the 6 used up pens in the recycle bin we are left with:
8 pens - 6 pens = 2 pens
To write this in MATLAB we would use
8-6
Subtraction of Column Vectors
If we started off with 8 pens and 5 pads and used up 6 pens and 3 pads then
Written as a column vector we will have:
To write this in MATLAB we would use
[8;5]-[6;3]
Subtraction of a Matrices
Okay so far, so good. Let's make things slightly more complicated again the man living in the red house has 8 pens and 5 pads and consumes 6 pens and 3 pads and the woman has 9 pens and 7 pads and consumes 8 pens and 4 pads. The man should therefore be left with 2 pens and 2 pads while the woman should be left with 1 pen and 3 pads
To write this in MATLAB we would use
[8,9;5,7]-[6,8;3,4]