arrays - How to store slider values in a vector -
i'm using matlab create gui. herefore i'm using guide function of matlab. want store slider values in vector. doing in callback function:
for = 1:10 x(i) = get(handles.slider1,'value'); end
but results in vector stores same value 10 times. want store last 10 values of slider in vector. ideas?
i suggest create 1 x 10
vector of zeros when starting gui, i.e. in openingfcn
of gui:
handles.x = zeros(1,10); guidata(hobject,handles); % update handles variable
then in callback function of slider, shift vector 1 right , add new value in first place:
x = get(handles.slider1,'value'); handles.x = [x, handles.x(1:end-1)]; guidata(hobject,handles); % update handles variable
now x
contains last 10 values of slider value, x(1)
last value , on.
before slider hasn't been moved 10 times, of values not correct, i.e. zero. if problem, grow x
vector dynamically in callback.
Comments
Post a Comment