[4693] | 1 | function animatesww2d_alt(sww_filename,movie_filename,range) |
---|
| 2 | |
---|
| 3 | nc2mat(sww_filename,'swwtemp.mat'); %convert .sww to .mat |
---|
| 4 | |
---|
[4698] | 5 | load('swwtemp.mat'); % load the data from the temporary .mat file |
---|
[4693] | 6 | |
---|
[4698] | 7 | figure(1); % Create a new figure |
---|
[4693] | 8 | |
---|
| 9 | if nargin > 1 |
---|
[4698] | 10 | % If we're making an animation then set the figure location and prepare |
---|
| 11 | % the avi file |
---|
[4693] | 12 | figure(1);set(gcf,'Position',[200 400 800 300]); |
---|
| 13 | mov=avifile(movie_filename,'FPS',5) |
---|
| 14 | end |
---|
| 15 | |
---|
[4698] | 16 | i=find(V_y==0); % Find all the points which lie along the x-axis |
---|
| 17 | % This could be made more general, or done in a way that is |
---|
| 18 | % safer against rounding-off errors. |
---|
| 19 | % |
---|
| 20 | % 'i' becomes a vector containing the indices of those points |
---|
| 21 | % which are on the x-axis. |
---|
[4693] | 22 | |
---|
| 23 | if nargin < 3 |
---|
[4698] | 24 | % If we don't specify the range to plot on the axes, then set it |
---|
| 25 | % here. X-axis covers the range in V_x, and the y-axis is 1 metre |
---|
| 26 | % outside the range of values in V_stage. |
---|
[4693] | 27 | range=[min(V_x) max(V_x) min(min(V_stage))-1 max(max(V_stage))+1]; |
---|
| 28 | end |
---|
| 29 | |
---|
[4698] | 30 | m=V_stage(1,i); % m is the vector containing the maximum stage values found |
---|
| 31 | % so far among the points selected with 'i'. |
---|
[4693] | 32 | |
---|
| 33 | for t=1:length(V_time) |
---|
| 34 | |
---|
[4698] | 35 | m=max(m,V_stage(t,i)); % update the vector of maximum values |
---|
| 36 | |
---|
[4693] | 37 | plot(V_x(i),V_stage(t,i),V_x(i),V_elevation(i),V_x(i),m,'.'); |
---|
[4698] | 38 | % Plot the stage of the points that are selected using the vector 'i' |
---|
| 39 | |
---|
[4693] | 40 | axis(range) |
---|
[4698] | 41 | % set the range of the axes |
---|
[4693] | 42 | |
---|
| 43 | title(num2str(V_time(t)));drawnow; |
---|
[4698] | 44 | % label with the time |
---|
| 45 | |
---|
[4693] | 46 | if nargin>1 |
---|
[4698] | 47 | % If we're making an animation then add a new frame |
---|
[4693] | 48 | F=getframe(gcf); |
---|
| 49 | mov=addframe(mov,F); |
---|
| 50 | end |
---|
| 51 | |
---|
| 52 | end |
---|
| 53 | |
---|
| 54 | if nargin > 1 |
---|
[4698] | 55 | % Close the animation file if necessary |
---|
[4693] | 56 | mov=close(mov); |
---|
| 57 | end |
---|