user972276
user972276

Reputation: 3053

3d plotting of a 2d matrix in matlab

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?

Upvotes: 7

Views: 37704

Answers (2)

sagunms
sagunms

Reputation: 8515

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

Upvotes: 3

Related Questions