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]

 Accepted Answer

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 Comments

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.
cheers mate this really helped
Cheers indeed!
Thank you!

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!