Hello there!

I want to find out how I can subtract the elements of a matrix from one another in a particular order. Lets say that I have the following matrix:

` matrix_1 = [30 39 42; 10 15 22; 1 5 7]`

This matrix represents the running total counts of some function. To get the counts for each individual cell, I want to subtract the element in a cell from the one before it. In this case, the solution will do something like this:

` matrix_2 = [30-22 39-30 42-39; 10-7 15-10 22-15; 1 5-1 7-5]`

in order to produce:

` matrix_3 = [8 9 12; 3 5 7; 1 4 2]`

Does anyone know of a way I can automize this process so I don't need to calculate this by hand?

Thank you in advanced!

Sincerely,

Colin

## Best Answer