Sign up ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I am trying to plot 3-D figure in matlab. I know how to use plot3 and surface. But now I have a vector and no a matrix. Actually I have $(x,y)$ and $u(x,y)$ that $u(x,y)$ is obtained after solving my problem. when I using plot with mesh, my figure is not true. please help me.

share|cite|improve this question

closed as off-topic by SHOBHIT GAUTAM, Nick Peterson, azimut, amWhy, Lord_Farin Oct 29 '13 at 18:35

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question is not about mathematics, within the scope defined in the help center." – SHOBHIT GAUTAM, Nick Peterson, azimut, amWhy, Lord_Farin
If this question can be reworded to fit the rules in the help center, please edit the question.

Thanks for your helps – Rosa Jan 16 '13 at 13:14

2 Answers 2

Let's say that you put a grid in two vectors x and y, then you could do the following.

share|cite|improve this answer
Thanks. But $u$ is $78\times 1$. I constructed a $78\times 78$Matrix but my figure was not true. Am I wrong? – Rosa Jan 16 '13 at 12:41
@Hakha You said that U is 78x1. How could that be? If either of x or y is constant, then you do not need a 3d plot but rather a 2d plot. – Learner Jan 16 '13 at 12:43
I have two vector $78\times 1$ $X and ~~Y$ and by these I construct vector $u(x,y)$ – Rosa Jan 16 '13 at 12:47
@Hakha Ok, for that case, just look at my edit. – Learner Jan 16 '13 at 12:51
@Learner If x and y are vectors of length $n$ and $Z$ is and $n\times n$ matrix, then you can use 'surf(x,y,Z)'. Surf will treat this as the set of triplets (x(i), y(j), Z(i,j)). This is especially important when $n$ is large as the two matrices produces by meshgrid are much larger. – Daryl Jan 16 '13 at 21:37

You have two vectors that define the sample points in x and y. To get all the points in the x-y domain you can use MESHGRID, as was suggested by learner. MESHGZRID will do a Cartesian product of the two sets X and Y. Then you can use those points to generate your function $u(x,y)$. Then you can use the full domain of x and y to plot u. Showing this with an example function $u(x,y) = x + y$ (note the case difference in variable names):

[X, Y] = meshgrid(x,y);
u = X + Y;
share|cite|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.