Contour plot with a circular boundary

17 visualizaciones (últimos 30 días)
tmu
tmu el 22 de Nov. de 2017
Editada: tmu el 24 de Nov. de 2017
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.

Respuesta aceptada

Image Analyst
Image Analyst el 22 de Nov. de 2017
Write back if you can't figure out how to adapt it to your needs.
  1 comentario
tmu
tmu el 23 de Nov. de 2017
Editada: tmu el 24 de Nov. de 2017
Thanks for pointing me in the right direction but I'm still not quite sure how to proceed. I don't know how to get the data values to right format for the contourf-function.
EDIT: Managed to do a circular boundary with the following code. I interpolated the data to circles with radii 0, 50 and 100. Not sure if this is the correct way to do it but the graph looks ok.
% 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];
% Create polar data
[t,r] = meshgrid((0:1:360)*pi/180,[0 50 100]);
% Convert to Cartesian
[X,Y] = pol2cart(t,r);
F = scatteredInterpolant(testX',testY',testZ');
Z = F(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);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Weather and Atmospheric Science en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by