Contour plot in hexagon form
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Kelly Kearney
le 17 Août 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);
0 commentaires
Voir également
Catégories
En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!