function animatesww2d_alt(sww_filename,movie_filename,range) nc2mat(sww_filename,'swwtemp.mat'); %convert .sww to .mat load('swwtemp.mat'); % load the data from the temporary .mat file figure(1); % Create a new figure if nargin > 1 % If we're making an animation then set the figure location and prepare % the avi file figure(1);set(gcf,'Position',[200 400 800 300]); mov=avifile(movie_filename,'FPS',5) end i=find(V_y==0); % Find all the points which lie along the x-axis % This could be made more general, or done in a way that is % safer against rounding-off errors. % % 'i' becomes a vector containing the indices of those points % which are on the x-axis. if nargin < 3 % If we don't specify the range to plot on the axes, then set it % here. X-axis covers the range in V_x, and the y-axis is 1 metre % outside the range of values in V_stage. range=[min(V_x) max(V_x) min(min(V_stage))-1 max(max(V_stage))+1]; end m=V_stage(1,i); % m is the vector containing the maximum stage values found % so far among the points selected with 'i'. for t=1:length(V_time) m=max(m,V_stage(t,i)); % update the vector of maximum values plot(V_x(i),V_stage(t,i),V_x(i),V_elevation(i),V_x(i),m,'.'); % Plot the stage of the points that are selected using the vector 'i' axis(range) % set the range of the axes title(num2str(V_time(t)));drawnow; % label with the time if nargin>1 % If we're making an animation then add a new frame F=getframe(gcf); mov=addframe(mov,F); end end if nargin > 1 % Close the animation file if necessary mov=close(mov); end