james42
james42

Reputation: 307

Division between rows of a matrix in Matlab

I'm having some problems performing a division between rows of a matrix in Matlab; i.e. dividing two subsequent rows elementwise. E.g., I need to write a function that transforms the following matrix A into the matrix B:

A = [1, 2, 3; 4, 5, 6; 7, 8, 9]

B = [4, 2.5, 2; 1.75, 1.6, 1.5]

How can I do this?

Edit: Obviously the above is just a toy example, I need to find a solution that can be extended easily to higher order matrices.

Upvotes: 1

Views: 98

Answers (1)

Chris Taylor
Chris Taylor

Reputation: 47402

You could do

>> A = [1 2 3; 4 5 6; 7 8 9];
>> B = A(2:end, :) ./ A(1:end-1, :)
B = 
    [ 4.0    2.5   2
      1.75   1.6   1.5 ]

Upvotes: 5

Related Questions