How can I plot a mesh?

13 views (last 30 days)
Shahid Iqbal
Shahid Iqbal on 9 Jul 2015
Answered: Star Strider on 9 Jul 2015
I have three variables X,Y and Z, Z is calculated from row vectors of X and Y and then I want to plot a mesh of Z using X and Y as grid... I know how to meshgrid but I dont know how to extend Z vector corresponding to X and Y grid?

Accepted Answer

Star Strider
Star Strider on 9 Jul 2015
Use meshgrid to create the ‘X’ and ‘Y’ meshes, then calculate ‘Z’ from them:
x = linspace(-3, 3, 50);
y = linspace(-1.5, 1.5, 30);
[X,Y] = meshgrid(x, y);
Z = sin(X) .* exp(Y);
figure(1)
mesh(X, Y, Z)
grid on
Note the use of element-wise multiplication (.*) in ‘Z’.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!