animation - Matlab assignin('base',...) Resets -
i attempting write function that, if called before animation, handle close events without code in animation file.
function matlabstopfunction(varargin) persistent runs if runs==2 runs = []; end if isempty(runs) evalin('base','figure(''deletefcn'',@matlabstopfunction);'); runs = 1; else assignin('base','play',false); pause(1); runs = 2; end end here's sample animation code i've been using:
function sampleanimation matlabstopfunction; r = 5; th = 0; play = true; while play x = r * cosd(th); y = r * -sind(th); plot(x,y,'r*'); axis([-10 10 -10 10]); th = th + 45; pause(0.25); end end the stop function works fine creating figure, , when close figure, calls same function expected (including assignin on line 10). however, when stepping through, when first base function (sampleanimation), play false expected: 
but when step 1 more line, play reset true

am incorrectly assigning value of play false in stop function, , if so, how correct animation stops when figure closed while keeping code inside animation minimum? trying replicate method on this blog except code contained in separate file.
i running matlab 2014b on windows 8.1.
to answer question - modifying value play in base workspace - loop in workspace of sampleanimation function -> not changing required value stop animation. verify clear variables in base workspace clear before run code , see variable play created , set false.
by way there simpler way this, animation can create figure , can stop when deleted:
function sampleanimation h = figure; r = 5; th = 0; while ishandle ( h ) x = r * cosd(th); y = r * -sind(th); plot(x,y,'r*'); axis([-10 10 -10 10]); th = th + 45; pause(0.25); end end
Comments
Post a Comment