Well, the following runs but isn't yet ready for prime time...needs some "prettying-up" to move the slider out of the way from occluding the axes; would probably be worth putting a text box to display the trace number and range and a few other niceties, but it does work...
function lydon(x,y)
hFig = figure('Visible','off');
hAx = axes;
tt=1;
NDataPoints=100;
gg=NDataPoints;
nTraces=fix(length(y)/NDataPoints);
ss1=1/(nTraces-1);
hL=plot(x(tt:gg),y(tt:gg),'k');
uicontrol('Style', 'slider',...
'Min',1, ...
'Max',nTraces, ...
'Value',1,...
'SliderStep',[ss1 ss1], ...
'Position', [400 20 120 20],...
'Callback', @src);
hFig.Visible='on'
function src(source,event)
val = get(source, 'Value');
i1=1+(val-1)*NDataPoints;
i2=val*NDataPoints;
set(hL,'XData',x(i1:i2),'YData',y(i1:i2))
end
end
My release doesn't yet support functions in script files so to have everything global I used the internal function within the outer function. You thus must call the main function with the two argument x,y vectors.
This works to make the slider move in increments of 1:nTraces in the overall input vector to move from one to the next and not have to worry about whether the indices were integer or not.
Using 1/(nTraces-1) as the minor and major step values means each click moves one trace; you could make the major a multiple of the minor if there are typically so many that the movement in single trace increments gets too tedious but for the 1:10 range I used for testing it works pretty well this way.
The biggest problem in your original was in not following the exact outline of the example and having two arguments in the callback instead of just the callback function handle...with that it then ran; rest was cleaning up initial values and the index calculations.