Contour plot with a circular boundary

16 次查看(过去 30 天)
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.

采纳的回答

Image Analyst
Image Analyst 2017-11-22
Write back if you can't figure out how to adapt it to your needs.
  1 个评论
tmu
tmu 2017-11-23
编辑:tmu 2017-11-24
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Weather and Atmospheric Science 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by