How to calculate log(a/b) for each two rows at each column ?

2 visualizaciones (últimos 30 días)
I have a matrix mXn for example
a = 2 3 6 5 7 4
5 4 7 8 9 6
4 5 8 9 8 5
And from above 3X6 matrix i want to calculate log(second row/first rown) at each column
Then finally I will have 2X6 matrix
How can I solve for mXn matrix ?
I use this code
for i = 1:3
for j = 1:6
dlogd = log(a(i+1,j)/a(i,j));
end
end

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 25 de Mayo de 2020
Editada: Ameer Hamza el 25 de Mayo de 2020
a = ...
[2 3 6 5 7 4
5 4 7 8 9 6
4 5 8 9 8 5];
b = log(a(2:end, :)./a(1:end-1,:));
Result
>> b
b =
0.9163 0.2877 0.1542 0.4700 0.2513 0.4055
-0.2231 0.2231 0.1335 0.1178 -0.1178 -0.1823
  4 comentarios
John D'Errico
John D'Errico el 25 de Mayo de 2020
It seemed clear this was just a slip of the brain.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by