Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help >  programs >  matlab

Matlab - Experimental data

Getting the data into matlab

Interpolation

Some of the more useful matlab commands require the data to be on a regular grid. Suppose you have experimental data z for a function of 2 variables, x and y, but those results don't lie on a regular grid (if you have no experimental date you can use the following to generate test data
  v=1:100;
  x=100*rand(size(v));
  y=100*rand(size(v));
  z=50*rand(size(v));
). You can prepare this data for use with griddata
% First define a regular grid. Suppose x and y are between 0 and 100.
% We'll set up a 201x201 grid
steps = 0:.5:100;
[XI,YI] = meshgrid(steps, steps);
% XI and YI will both be 201x201. XI contains the x-coords of each point and
% YI contains the y-coords.

% now interpolate - find z values for these grid points
ZI = griddata(x,y,z,XI, YI);
% The z values in ZI can now be used by routines like contour, etc.
% Display this as a mesh 
mesh(XI,YI,ZI);
hold
% plot the original data too
plot3(x,y,z);
hold off

Matlab 5.3 has improved 3D interpolation facilities. Type "help vissuite" to list the routines in the Visualization Suite.

In experimental data you might have missing values. The inpaint_nans routine should smoothly interpolate any nans that it finds in an array based on the neighbors of those points.

© Cambridge University Engineering Dept
Information provided by Tim Love (tpl)
Last updated: June 2008