7

I have an MxN matrix, Z, and some variable h. This matrix represents the points to a solution of a function f(x,y). h is the spacing between points. For instance:

Z(x/h,y/h) = (some value in the Z direction), where x and y are some multiple of h

The domain is from 0 to M*h and the range is from 0 to N*h. I would like to make a 3d representation of the solution defined by the matrix. The graph should be similar to what is produced using the pdetool. How do I do this in Matlab?

2 Answers 2

11

You can use surf or bar3.

Here is the documentation:

surf: http://www.mathworks.fr/help/matlab/ref/surf.html;jsessionid=c680a6b29a1fa8ff47c120353c12

enter image description here

bar3: http://www.mathworks.fr/fr/help/matlab/ref/bar3.html enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks! I think surf is what I am wanting. Is there a way to use the surf command and define a non-rectangular domain? Basically I have a region of the matrix that I do not want to plot.
as described in the documentation, you can use surf(X,Y,Z) to specify the (X,Y) position of each Z. This can be used to have holes in your stuff. I cannot give more details without more explanation about your holes. Maybe ask a separate question.
yeah but if I set X to something like [0,h,2h,2h,...] and Y similarly, how does that produce holes? It says I can specify X and Y as a matrix but I dont understand how that would work. I will ask in a separate question.
X and Y should have the same size than Z
yeah but what is the (x,y) coordinate for a point in Z that should not be graphed? I cant make it (0,0) or something cause all the Z points will just go to (0,0).
3

Here is an example of using surf to plot a 2D matrix in Matlab.

Code:

x_offset = [78, 216, 150, 342, 258, 336;
            168, 174, 174, 222, 150, 246;
            36, 180, 54, 138, 138, 198;
            60, -72, 90, 66, 114, 36;
            -90, -108, -60, 12, 54, -24;
            -42, -78, -138, -42, -12, -114;
            -108, -30, -108, -66, -156, -114;
            -66, -114, -114, -84, -138, -96];
figure(1), surf(x_offset);
xlabel('X'), ylabel('Y'), title('X-offset Error Distribution');

Output:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.