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

difference between columnsmatrix operations

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!

Best Answer

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