If I have an array such as:
R = [0, 0, 4, 0, 1, 0, 0, 0, 0, 6];
I want to code it so that all elements are checked and if the number in that element is greater than the gap between it and the next non-zero element, it is reduced to the (gap distance minus 1)
IE, R(1), R(2) etc are 0 so remains 0. R(3) is checked to be 4, has a distance of 2 until the next non-zero entry so is reduced to 1. R(5) is checked to be 1, there is no non-zero entry within 1 space so it remains 1. R(10) is 6 and has a distance of 3 until the next non zero entry so is reduced to 2. etc
Sorry if that's poorly explained. I'm very new to Matlab and this one has stumped me so any help or starting points will be appreciated.