% Illustrates use of 'load' command to load array from file,
% and then plot it as a surface plot using surf ...

% Generate test data and save it.
nxout = 51;
ntout = 51;
xout = linspace(0.0,3*pi,nxout);
tout = linspace(0.0,3*pi,ntout)';

xxout = ones(ntout,1) * xout;
ttout = tout * ones(1,nxout);
uout = cos(xxout).*sin(0.5*ttout);

disp 'saving as u.dat'
save '-ascii' u.dat uout

% Load array---formatted as one row per line---in this case from
% file 'u.dat'
disp 'Loading u.dat' 
u = load('-ascii', 'u.dat');
[nt, nx] = size(u);
% x and t (y) coordinates are (arbitrarily) set to 1 .. nx and 
% 1 .. ny.
x = 1:nx;
t = [1:nt]';
xx = ones(nt,1) * x;
tt = t * ones(1,nx);
surf(xx,tt,u);
% Save plot as .gif image.
print('u.gif','-dgif');
