Contour plot in hexagon form
이전 댓글 표시
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
2016년 8월 17일
why dont you attach file here? Going to dropbox logging in is head ache...
Protik Das
2016년 8월 17일
답변 (1개)
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);
카테고리
도움말 센터 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!