Contour plot with a circular boundary
17 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Weather and Atmospheric Science in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!