24 Write a function that computes the next LED to control

In MATLAB edit the function named nextIndex that computes the index of the next LED to control. The function should satisfy all of the following requirements:

  1. it should return a value named next
  2. it should be named nextIndex
  3. it should have one input variable called curr that is equal to the index of the LED that was most recently turned on or off
  4. it should return next the index of the next LED to blink given the index curr of the LED that was most recently turned on or off

For example:

  • nextIndex(0) should return 1
  • nextIndex(1) should return 2
  • nextIndex(2) should return 3
  • nextIndex(3) should return 0
  • nextIndex(4) should return 1
  • nextIndex(5) should return 2
  • nextIndex(6) should return 3
  • nextIndex(7) should return 0
  • and so on

Your function should not use any if statements or switch statements; instead, you should simply wrap the value curr + 1 to the range 0 to 3 using mod or rem.

Test your function in the MATLAB Command Window to ensure that your function returns the expected values shown above.