MATLAB: Vector Difference vector math Given a vector x=[2 5 6 10 16 29]. Is there a one line command to create another vector that is the difference between the last elements (first element of x is first element of y)? Example Output: y=[2 3 1 4 6 13] Best Answer y = [x(1) diff(x)] Related SolutionsMATLAB: How to determine number of common elements between two vectors numel( intersect( X, Y ) ) MATLAB: Difference If I remember correctly, diff works across the first non-singleton dimension. So diff(A) works across columns and diff(A(1, :)) works across rows.x = [1,2,3; 4,5,6];diff(x, [], 1)ans = 3 3 3diff(x, [], 2)ans = 1 1 1 1 Related QuestionDifference matrix?How to substitute some elements from a vectorVector Equation with scalarsSimple operation with vectorsFrame Difference
Best Answer