Contour plot in hexagon form

6 次查看(过去 30 天)
Protik Das
Protik Das 2016-8-17
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 个评论
KSSV
KSSV 2016-8-17
why dont you attach file here? Going to dropbox logging in is head ache...
Protik Das
Protik Das 2016-8-17
You can download the file without logging in. Anyway I updated the file.

请先登录,再进行评论。

回答(1 个)

Kelly Kearney
Kelly Kearney 2016-8-17
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);

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by