Contour plot with a circular boundary

17 ビュー (過去 30 日間)
tmu
tmu 2017 年 11 月 22 日
編集済み: tmu 2017 年 11 月 24 日
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 Center および File ExchangeWeather and Atmospheric Science についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by