I have an x and y data coordinates of an l shaped plate and z data of corresponding displacements and each matrix is 23 rows.
can anyone help me draw a 2d filled contour plot
x = [0;0.03;0.03;0.01;0.01;0;0.02;0.02;0.01;0;0.01;0.02;0.015;0.005;0.025;0.03;0.025;0.01;0.005;0;0.01;0.005;0]
y = [0;0;0.01;0.01;0.04;0.04;0;0.01;0.025;0.025;0;0.005;0.01;0.005;0;0.005;0.01;0.0175;0.025;0.0125;0.0325;0.04;0.0325]
z = [0.002071017;0.002090221;0.001384402;0.001358957;0;0;0.002078694;0.001373731;0.000432053;0.000422168;0.002069412;0.001727074;0.001369789;0.001713017;0.002084764;0.00173648;0.00137873;0.000855225;0.000414625;0.001187851;0.000125043;0;0.000124721]

 採用された回答

Star Strider
Star Strider 2021 年 1 月 8 日

0 投票

Try this:
x = [0;0.03;0.03;0.01;0.01;0;0.02;0.02;0.01;0;0.01;0.02;0.015;0.005;0.025;0.03;0.025;0.01;0.005;0;0.01;0.005;0];
y = [0;0;0.01;0.01;0.04;0.04;0;0.01;0.025;0.025;0;0.005;0.01;0.005;0;0.005;0.01;0.0175;0.025;0.0125;0.0325;0.04;0.0325];
z = [0.002071017;0.002090221;0.001384402;0.001358957;0;0;0.002078694;0.001373731;0.000432053;0.000422168;0.002069412;0.001727074;0.001369789;0.001713017;0.002084764;0.00173648;0.00137873;0.000855225;0.000414625;0.001187851;0.000125043;0;0.000124721];
N = 15;
xv = linspace(min(x), max(x), N);
yv = linspace(min(y), max(y), N);
[X,Y] = ndgrid(xv, yv);
Z = griddata(x,y,z,X,Y,'linear');
figure
contourf(X, Y, Z, 'ShowText','on')
xlabel('x')
ylabel('y')
Change ’N’ to get different results.

4 件のコメント

Shehab Abougamrah
Shehab Abougamrah 2021 年 1 月 8 日
the problem is the graph came out like this it went beyond the geometry and my geometry is l shaped
Star Strider
Star Strider 2021 年 1 月 8 日
I went back and plotted your original data to understand what you want.
Add this assignment to limit ‘Z’ appropriately:
Z((X>=0.01) & (Y>=0.01)) = NaN;
so the code is now:
x = [0;0.03;0.03;0.01;0.01;0;0.02;0.02;0.01;0;0.01;0.02;0.015;0.005;0.025;0.03;0.025;0.01;0.005;0;0.01;0.005;0];
y = [0;0;0.01;0.01;0.04;0.04;0;0.01;0.025;0.025;0;0.005;0.01;0.005;0;0.005;0.01;0.0175;0.025;0.0125;0.0325;0.04;0.0325];
z = [0.002071017;0.002090221;0.001384402;0.001358957;0;0;0.002078694;0.001373731;0.000432053;0.000422168;0.002069412;0.001727074;0.001369789;0.001713017;0.002084764;0.00173648;0.00137873;0.000855225;0.000414625;0.001187851;0.000125043;0;0.000124721];
N = 150;
xv = linspace(min(x), max(x), N);
yv = linspace(min(y), max(y), N);
[X,Y] = ndgrid(xv, yv);
Z = griddata(x,y,z,X,Y,'linear');
Z((X>=0.01) & (Y>=0.01)) = NaN;
figure
contourf(X, Y, Z, 'ShowText','on')
xlabel('x')
ylabel('y')
producing this filled contour plot:
See the documentation for contourf to change the number of contours or to define specific contours, among other options.
Shehab Abougamrah
Shehab Abougamrah 2021 年 1 月 8 日
cheers mate this really helped
Star Strider
Star Strider 2021 年 1 月 8 日
Cheers indeed!
Thank you!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by