1

I have a data set on the form of 3 spatial coordinates x,y,z and an amplitude, here is a small crop of the data:

[        0    2.9373    0.4646    2.9926
    0.8384    1.5338    1.0000    1.0016
         0    0.7619    0.5051    1.0033
    1.0000    3.5288    0.6667    2.9894
         0    0.5013    0.4343    1.0037
    1.0000    2.8070    0.4848    2.9935
    0.7980    4.0000    0.8586    2.9872
    1.0000    0.1404    0.0707    1.0043
    1.0000    1.7845    0.1818    1.0007
    0.9798    3.1679    1.0000    2.9913]

What I would like is a 2D contour plot, where the interface is represented by the contour levels within, say, 2.0 +/- 0.05.

First I start by making the data 2D and thus choose the values z within +/- 0.01. Then I am only left with x,y,amplitude.

Then I used this for extracting the data sets that satisfy data(:,4) is within 2.0 +/- 0.05.

However, what remains now is actually making the contour plot. I tried contour but that requires the data to have a format of meshgrid, which it does not. So my question is, what is the easiest way to make a contour plot of the extracted data?

Community
  • 1
  • 1
BillyJean
  • 1,537
  • 1
  • 22
  • 39
  • I posted an answer but realized it won't work. Contour is meant for 2D data only. You will have to do something like use the `isosurface` function. Check out [this answer](http://stackoverflow.com/questions/15684023/how-to-plot-4d-contour-lines-xyz-v-in-matlab). – Brian Lynch Oct 21 '15 at 09:41
  • @BrianLynch Thanks. I reformulated my question to be applicable to 2D as well, would like to hear your suggestions – BillyJean Oct 21 '15 at 09:44
  • That is much easier to solve, I edited my answer but didn't check it thoroughly yet. – Brian Lynch Oct 21 '15 at 10:09

1 Answers1

0

You should be able to create an interpolation function for your scattered data like this:

F_interp = scatteredInterpolant(x,y,amplitude);

Then setup a gridded mesh of interpolation points (using limits and sizes that could be based on the original data):

xMin = min(x);
xMax = max(x);
yMin = min(y);
yMax = max(y);
Nx = 2*length(x);
Ny = 2*length(y);
xpts = linspace(xMin,xMax,Nx);
ypts = linspace(yMin,yMax,Ny);
[X,Y] = meshgrid(xpts,ypts);

Interpolate the data at those gridded points:

A = F_interp(X,Y);

Now pass the interpolated data to the MATLAB contour function:

contour(X,Y,A);
Brian Lynch
  • 542
  • 5
  • 13