Borrar filtros
Borrar filtros

Difference between columns, fixed the first column, in a matrix

1 visualización (últimos 30 días)
Hi, I have a 3D-matrix and I want to calculate differences between columns, fixed the first column, and the value be positive or zero, i.e., for each 3D dimension calculate: max ( column(i)-column(1), 0 ). For example:
Thank you in advance!

Respuesta aceptada

Adam
Adam el 3 de Nov. de 2017
Editada: Adam el 3 de Nov. de 2017
res = max( 0, A(:,2:end,:) - A(:,1,:) );
Note: This syntax only works from R2016b. For older syntax see Andrei Bobrov's answer

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 3 de Nov. de 2017
Editada: Andrei Bobrov el 3 de Nov. de 2017
B = bsxfun(@minus,A(:,2:end,:),A(:,1,:));
B(B<0) = 0;

Categorías

Más información sobre Elementary Math 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