Contour plot in hexagon form
Mostrar comentarios más antiguos
I have some data for a evenly distributed grid inside a hexagon. I would like to do a contour plot which will look like this:

The data I am trying to plot is uploaded in a MAT file here. Here x and y are the horizontal and vertical values of coordinates respectively.
The plot of the coordinates looks like this:

What I have tried to do is given below,
clearvars;
load('data.mat');
[X,Y]= meshgrid(x, y);
lx=length(X);
Z= zeros(lx,lx); % initializing matrix
nopoints=length(x);
count=1;
for ix=1:lx
for iy=1:lx
if (count <= nopoints)
if(X(ix,iy)==x(count) && Y(ix,iy)==y(count))
Z(ix,iy)=z(count);
count = count+1;
else
Z(ix,iy) = NaN;
end
else
Z(ix,iy)= NaN;
end
end
end
figure;
contour(X,Y,Z);
Unfortunately the plot shows nothing like the first image. With data cursor I can see there are discrete data points but no contour plot. Am I missing something?
Any help regarding this is greatly appreciated. :)
2 comentarios
KSSV
el 17 de Ag. de 2016
why dont you attach file here? Going to dropbox logging in is head ache...
Protik Das
el 17 de Ag. de 2016
Respuestas (1)
Kelly Kearney
el 17 de Ag. de 2016
Take a look at the sparsity pattern of the matrix you built to represent your grid:
spy(~isnan(Z))
I don't entirely follow the logic of your code, but it's definitely not gridding the data like you want. The easiest way to do this is with scatteredInterpolant:
f = scatteredInterpolant([x y], z, 'nearest', 'none');
[xg, yg] = meshgrid(unique(x), unique(round(y,2)));
zg = f(xg,yg);
scatter(x,y,[],z);
hold on;
contour(xg,yg,zg);
Categorías
Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!