Make sure that round(f)
gives you value greater 0
.
If round(f) == 0
, you'll end up with indexing starting from zero:
> f=0; f:f + 4 - 1
ans =
0 1 2 3
> f=1; f:f + 4 - 1
ans =
1 2 3 4
Added: To avoid this you should play with Min
, Max
, and SliderStep
properties of your slider so Value
will return you integer values (or at least values very close to integers witj minimal round-off errors).
For example, if you want
Slider.Min = 1;
Slider.Max = 79;
Then you should put
Slider.SliderStep = [1 10] / ( Slider.Max - Slider.Min )
In this case click on the slider button with arrow will increase slider value by 1, but when you click the slider trough, slider value will increase by 10.
See documentation on the SliderStep
property of uicocntrol
for more explanations.