% Illustrates use of
% of load command to load a 2D array (matric) from 
% 
% a text (ASCII) file, and then plot it as a surface plot using surf.

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

xxout = ones(nyout,1) * xout;
yyout = yout * ones(1,nxout);
fout = cos(xxout).*sin(0.5*yyout);

% Save to text file f.dat.
disp('saving as f.dat');
save('-ascii', 'f.dat', 'fout');

% Load array---interpreted as one row per line---from u.dat.
disp('Loading f.dat' );
u = load('-ascii', 'f.dat');

% Determine size of loaded array.
[nt, nx] = size(u);

% For plotting purposes, generate and use arbitrary x and y coordinates.
x = 1:nx;
t = [1:nt]';
xx = ones(nt,1) * x;
tt = t * ones(1,nx);

% Make the surface plot.
surf(xx,tt,u);

% Save plot as .jpg image, not that the second argument to print
% is '-djpeg', NOT '-djpg'.
print('f.jpg','-djpeg')
