I'm using Matlab to create a GUI. Herefore I'm using the guide function of matlab. I want to store the slider values in a vector. I am doing this in the callback function:
for i = 1:10
X(i) = get(handles.slider1,'Value');
end
But this results in a vector that stores the same value 10 times. What I actually want is to store the last 10 values of the slider in a vector. Any ideas?
I would suggest to create a
1 x 10
vector of zeros when starting the GUI, i.e. in theOpeningFcn
of the GUI:Then in the Callback function of the slider, you always shift the vector one to the right and add the new value in the first place:
Now
X
always contains the last 10 values of the slider value,X(1)
is the last value and so on.Before the slider hasn't been moved 10 times, some of the values will not be correct, i.e. they will just be zero. If this is a problem, you could grow the
X
vector dynamically in the Callback.