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
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 Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by