# Matlab mesh problem

• Mar 9th 2009, 08:59 AM
Matlab mesh problem
Hi,
I'm having a problem with the mesh & surf commands in Matlab. I am trying to plot a 3D contour, Z, in a limited area.

Using plot3 as follows works fine:

Code:

``` for theta1 = -0.5:0.05:2.5 for theta2 = -0.5:0.05:2.5   Z = ((0.1150 * sin(theta1) * cos(theta2) * 9.81 + 0.1150 * cos(theta1) * sin(theta2) * 9.81 + 0.3990 * sin(theta1) * g) ^ 2 / 20) + (0.00013)   plot3(theta1,theta2,Z);   end end```
But as mesh is clearer I'd prefer to use that.
However when I try following the Matlab example my plot seems to ignore one of my input arguments producing a Z matrix where all the rows are identical? I've spent quite a bit of time on this and just can't get the bottom of it. I'd realy appreciate any suggestions...

Here is my code:
Code:

``` [theta1,theta2] = meshgrid(-0.5:0.05:2.5); Z = ((0.1150 * sin(theta1) * cos(theta2) * 9.81 + 0.1150 * cos(theta1) * sin(theta2) * 9.81 + 0.3990 * sin(theta1) * g) ^ 2 / 20) + (0.00013) mesh(theta1,theta2,Z);```
Strangely ezmesh seems to work fine but I'd like to know why mesh doesn't like my equation (which plot3 does like).

Many Thanks,

• Mar 9th 2009, 11:37 AM
Sort of a solution
Just as a follow up for anyone else who is having this problem...

This method gives the result I wanted but I still don't know why my first method didn't work?

Code:

``` t1 = -0.5:0.1:3; t2 = -0.5:0.1:3;   Z = zeros(length(t1)); % create a matrix of n*n dimension   for(i = 1:length(Z2))  for(j = 1:length(Z2))   th1 = t1(i);   th2 = t2(j);     Z(i,j) = (my equation);    end end   mesh(t2,t1,Z)```

• Mar 9th 2009, 01:37 PM
CaptainBlack
Quote:

Hi,
I'm having a problem with the mesh & surf commands in Matlab. I am trying to plot a 3D contour, Z, in a limited area.

Using plot3 as follows works fine:

Code:

``` for theta1 = -0.5:0.05:2.5 for theta2 = -0.5:0.05:2.5   Z = ((0.1150 * sin(theta1) * cos(theta2) * 9.81 + 0.1150 * cos(theta1) * sin(theta2) * 9.81 + 0.3990 * sin(theta1) * g) ^ 2 / 20) + (0.00013)   plot3(theta1,theta2,Z);   end end```
But as mesh is clearer I'd prefer to use that.
However when I try following the Matlab example my plot seems to ignore one of my input arguments producing a Z matrix where all the rows are identical? I've spent quite a bit of time on this and just can't get the bottom of it. I'd realy appreciate any suggestions...

Here is my code:
Code:

``` [theta1,theta2] = meshgrid(-0.5:0.05:2.5); Z = ((0.1150 * sin(theta1) * cos(theta2) * 9.81 + 0.1150 * cos(theta1) * sin(theta2) * 9.81 + 0.3990 * sin(theta1) * g) ^ 2 / 20) + (0.00013) mesh(theta1,theta2,Z);```
Strangely ezmesh seems to work fine but I'd like to know why mesh doesn't like my equation (which plot3 does like).

Many Thanks,