Problem 42798. Moving Product (Easy)
Given an input array A, write a function movprod(A,k,dim) to calculate the moving product over a sliding window of length k along the specified dimension dim of input array A. If dim is omitted, operate along the first non-singleton dimension of A.
Example 1:
>> A = [1 2 3 4 5 6]; >> B = movprod(A,3) B = 6 24 60 120
Example 2:
>> A = [1 4 3 6 2 2 5 1 2 3 3 6 2 3 5]; >> B = movprod(A,3,2) B = 12 72 36 10 10 6 36 36 30
You may assume that dim <= 3, and the input array A is a non-empty array with size(A,dim) >= k.
Related problems: Problem 429; Problem 246
A kind note (05/15/2017): This problem was created in 2016, one year before R2017a's introduction of the built-in movprod. To avoid function name clash, we've changed the user-defined function name into moveprod in the test-suite, which gives you the opportunity to solve the problem by directly calling the built-in movprod!
Solution Stats
Problem Comments
Solution Comments
Show commentsGroup

The Prime Directive
- 14 Problems
- 37 Finishers
- Find the nearest prime number
- Extra safe primes
- Prime factor digits
- Twin Primes
- Twins in a Window
- The Goldbach Conjecture
- The Goldbach Conjecture, Part 2
- Goldbach's marginal conjecture - Write integer as sum of three primes
- Sophie Germain prime
- Mersenne Primes vs. All Primes
- Circular Primes (based on Project Euler, problem 35)
- Numbers spiral diagonals (Part 2)
- Pernicious Anniversary Problem
- Prime Ladders
Problem Recent Solvers33
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!