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?
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.