MATLAB: Subtracting elements with constraints

array

Hi all,
I have an array A and I need to subtract the elements of each column using the cumsum function:
B=bsxfun(@minus, A(1,:), cumsum(A(2:end,:)));
However I have some constraints that should not violated (min=1.3, max=11.7) Is there any way to do the calculations within these limits?
thanks

Best Answer

Your question is not clear where you want these constraints applied.
Option one: constrain output values:
B = bsxfun(@minus, A(1,:), cumsum(A(2:end,:)));
B = max(1.3, min(11.7, B));
Options two: constrain cumsum values:
tmp = max(1.3, min(11.7, cumsum(A(2:end,:))));
B = bsxfun(@minus, A(1,:), tmp);