Contour plot with a circular boundary
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a circular object which I sampled at nine locations and got some data. Now, I'd like to create a contour plot of the data but I do not know how to create one with a circular boundary.
I've managed to create a graph with the following code:
% Coordinates of data points and data.
testX = [100,0,-100,0,0,50,0,-50,0];
testY = [0,-100,0,100,0,0,-50,0,50];
testZ = [58.4542,51.5161,52.1838,55.8480,54.5418,51.9043,48.3288,47.7176,58.3356];
% Put the data to right format.
n=5;
[X,Y] = meshgrid(linspace(min(testX),max(testX),n), linspace(min(testY),max(testY),n));
Z = griddata(testX,testY,testZ,X,Y);
% Plot a graph.
figure
contourf(X,Y,Z,30,'LineColor', 'none');
daspect([1 1 1])
% Colormap
c = hsv;
c = c(1:45,:);
colormap(c);
Which produces:

But I'd like to get a graph where the boundary is circular, similar to this one hastily created in Origin:

I tried the following, but it's not quite right.
% Coordinates of data points and data.
testX = [100,0,-100,0,0,50,0,-50,0];
testY = [0,-100,0,100,0,0,-50,0,50];
testZ = [58.4542,51.5161,52.1838,55.8480,54.5418,51.9043,48.3288,47.7176,58.3356];
radius = 100;
decimals = 4;
% Create polar data
[r,t] = meshgrid(-radius:1:radius,0:pi/30:(2*pi));
% Convert to Cartesian
X = round(r.*cos(t),decimals);
Y = round(r.*sin(t),decimals);
Z = griddata(testX,testY,testZ,X,Y);
% Plot a graph.
figure
contourf(X,Y,Z,30,'LineColor', 'none');
daspect([1 1 1])
% Colormap
c = hsv;
c = c(1:45,:);
colormap(c);

Any help would be appreciated, thanks in advance.
0 commentaires
Réponse acceptée
Image Analyst
le 22 Nov 2017
Write back if you can't figure out how to adapt it to your needs.
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Weather and Atmospheric Science dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
