% Example of using the meshgrid command
% T. Trani (April 9, 2012)

% "Meshgrid" function is used to generate a grid of points along two dimensions
% Useful to generate grid data, do 3D plots or present data in 3-dimensions
% Example use:

% Structural engineering - to generate grids of beam and truss structures
% Traffic engineering - to generate discrete points of traffic flow
% phenomena
% Environmental engineering - to generate and visualize emissions and
% pollution

% Generate 2 vectors x and y

x=0:1:10;
y=10:1:35;

% Generate a grid of points along x and y

[xgrid,ygrid] = meshgrid(x,y);      % generates a rectangular matrix with grid points

% Generate a function (f(x,y) that depends on x and y

fxy  = xgrid.^0.4.*cos(ygrid/3)+sin(xgrid).*ygrid.^0.6;

% Plot the function fxy
% using the surf function in Matlab

surf(xgrid,ygrid,fxy)
xlabel('X values')
ylabel('Y values')
grid

