Compute the product of the next n elements in array
问题 I would like to compute the product of the next n adjacent elements of a matrix. The number n of elements to be multiplied should be given in function's input. For example for this input I should compute the product of every 3 consecutive elements, starting from the first. [p, ind] = max_product([1 2 2 1 3 1],3); This gives [1*2*2, 2*2*1, 2*1*3, 1*3*1] = [4,4,6,3] . Is there any practical way to do it? Now I do this using: for ii = 1:(length(v)-2) p = prod(v(ii:ii+n-1)); end where v is the