How to prepare and plot unequally spaced, irregular data to a contour plot or similar with MATLAB I've got a data set of hot-wire measurement velocity amplitudes at a given frequency bin (time data that has already been transformed to the frequency domain and I am just considering data for a given frequency bin) that have been sequentially recorded on specific locations in the xz-plane with a traverse-system. The problem is that the data does not represent a full uniform grid, but is sparsly sampled. Actually, the traversing process was performed in a way to get several locations within a given, more or less rectangular area, while avoiding hitting a circular obstacle within this area. Additionally, the regions close to the obstacle were sampled more densely as compared to regions farther away from the obstacle.

As a result the data set to start my problem with looks like the following  matrix (3 columns and e.g. 400 rows):

x z values (3 columns)

x1 z1 value1
x2 z2 value2
x3 z3 value3
.   .    .
.   .    .
.   .    .


(each value representing the velocity amplitude, e.g. at 500 Hz)

But the problem is:


The data was collected in some wierd order, e.g. the first 6 coordinates (x-component) are [-5; -5; -3; 10; 10; 0.8; ...] and the first 6 coordinates (z-component) are [0.2; 0.3; 5; 3; 2; -1; ...] ...
The data does not represent a uniform and equally spaced grid: all data (for example) lies within the range [-5 &lt;= x &lt;= 10] and [-2 &lt;= z &lt;= 6], but it is possible that there are 8 z-positions for one x-position, while at another x-position there are only 3 z-positions and at several other x-positions there are no z-positions at all (as within the obstacle region).
There is a greatest common divisor with respect to the grid resolution, e.g.    0.1   so all x and z-coordinates are positive or negative multiples of 0.1. This means it would be possible to generate a (probably) huge matrix (xz-plane) that includes all possible locations. I think this could help somehow.


What I basically want:

A simple contourf plot of the data within the xz-plane and areas that have not been recorded (obstacle region) are either interpolated or even better filled with NaNs (or Zeros) or something like that. Actually, I know the coordinates of the obstacle and might just draw it as overlay later.

Do you know how to get the desired result in a convenient manner?

I've been trying for ages now, but I just don't find a solution that solves my problem. I am pretty sure that it can be solved with some combination of reshaping, ndgrid/mesh, sorting or gridded interpolation with built-in (image  processing?) functions but I just don't get it to work.
I found a possible solution with the help of some collegue.

When gridis the matrix containing an x and a z and a value column (each having the same number of elements):

[X,Y] = ndgrid(linspace(min(grid(:,1)),max(grid(:,1)),150),linspace(min(grid(:,2)),max(grid(:,2)),150));
Z = griddata(grid(:,1),grid(:,2),grid(:,3),X,Y,'cubic');
contourf(X,Y,Z)
axis equal
scatter(grid(:,1),grid(:,2),10,grid(:,3),'wx');


So basically


a grid is generated with a relativly fine resolution (150x150 points) on basis of the min/max limits of the original data
the original data is interpolated onto this grid with a cubic interpolation method
contourf plot is generated and axis is set equal
the original data points are scattered onto the contourf plot to make sure that the interpretation of the data is somehow more reliable and one can see at once that the areas are interpolated.


I realized in between that the real difficulty is the obstacle area, as is gets wierdly interpolated although there should be no data, as none of the interpolation methods is used to such boundaries or optimized to those.