# Contour plot for a non rectangular object

35 ビュー (過去 30 日間)
Ghazwan 2022 年 10 月 5 日
コメント済み: William Rose 2022 年 10 月 6 日
I have this case that I worked out in another software. In the attached file, you can see the X,Y coordinates. The third column represents the results that I need to plot in a contour silimar to the one in the image above.
I tried several codes, but all of them plot on a rectagular area and/or not showing the same shape for the contour area. For example, the following code:
x=xyz(2:end,1);
y=xyz(2:end,2);
z=xyz(2:end,3);
[X,Y]=meshgrid(min(x):max(x),min(y):max(y));
Z=griddata(x,y,z,X,Y);
contour(X,Y,Z)

サインインしてコメントする。

### 採用された回答

William Rose 2022 年 10 月 5 日
[X,Y]=meshgrid(x,y) makes a grid where all the x values are the same across the grid, and likewise for yhe y values.
You can fix it by making your own X and Y instead of using meshgrid.
Nx=41; Ny=9;
x=((0:Nx-1)-(Nx-1)/2)*dx; y=((0:Ny-1)-(Ny-1)/2)*dy;
[X,Y]=meshgrid(x,y); %initial approximation
Z1=X+2*Y;
subplot(211); surf(X,Y,Z1);
xlabel('X'); ylabel('Y'); axis equal; view(0,90)
for i=1:Nx
if i<=5||i>=37
ymult=1;
elseif i>=32
ymult=(i-25)/12;
elseif i<=10
ymult=(17-i)/12;
else
ymult=0.5;
end
end It works. The code to adjust the y-values is not very elegant, but it demonstrates the possibilities for creating a non-retangular grid.
##### 4 件のコメント表示 3 件の古いコメント非表示 3 件の古いコメント
William Rose 2022 年 10 月 6 日
@Ghazwan, you are welcome. Your plan sounds good.

サインインしてコメントする。

### カテゴリ

Find more on Surface and Mesh Plots in Help Center and File Exchange

R2019a

### Community Treasure Hunt

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

Start Hunting!