Update Plot frame from slider call back

1 view (last 30 days)
Lawson Hoover
Lawson Hoover on 8 Dec 2012
I am trying to update an animated plot with a slider. Such that the value of the slider changes the plot to that frame in the animation. My code for the movie is:
plot(x,y,'--r','LineWidth',3); % original position
xlabel('Beam Length (in.)','Color','g');
ylabel(bstr,'Color','g');
ylim([-(Beam.y(10)) max(Beam.y)]);
title(astr,'Color','y','fontweight','b');
set(S.ax,'YDir','reverse');
set(S.ax,'XGrid','on');
set(S.ax,'YGrid','on');
xZero =0;
yZero = 0;
hold on % hold the orginal position plot and the axes properties
M(100) = struct('cdata',[], 'colormap', []); % preinitialization
ht = plot(xZero,yZero,'-b','linewidth',2); % new position
for i = 1:100 % Plots each new position on the graph animating the process
if i == 1
set(ht ,'XDataSource','Beam.x')
set(ht,'YDataSource','Beam.y')
end
set(ht,'XData',Beam.x(1:i))
set(ht,'YData',Beam.y(1:i))
M(i) = getframe(gcf);
end
legend('Without Deflection','With Deflection');
hold off
I then have a slider call back to gather all of the info. _Every time_ I use the slider though I get the error: Undefined function of variable 'ht' The code for my call back is:
function [] = sl_call_video(varargin)
%%%%%%%%%%%%%%Callback for the edit box and slider. %%%%%%%%%%%%%%%%%%%%%%
[h,S] = varargin{[1,3]}; % Get calling handle and structure.
SL = get(S.sl,{'min','value','max'}); % Get the slider's info.
E = str2double(get(h,'string')); % Numerical edit string.
%%%%%%%%%%%%%%%%%%%%%%%%%Actual Process %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch h % Who called?
case S.ed(2)
if E >= SL{1} && E <= SL{3}
set(S.sl,'value',E) % E falls within range of slider.
else
set(S.ed(2),'string',SL{2}) % User tried to set slider out of range.
end
case S.sl
set(S.ed(2),'string',round(SL{2}))% Set edit to current slider.
set(ht,'XData',Beam.x(1:SL{2}))
set(ht,'YData',Beam.y(1:SL{2}))
refreshdata
drawnow
otherwise
end
end

Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!