Reputation: 3053
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
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:
Upvotes: 3
Reputation: 16065
You can use surf
or bar3
.
Here is the documentation:
surf: http://www.mathworks.fr/help/matlab/ref/surf.html;jsessionid=c680a6b29a1fa8ff47c120353c12
bar3:
http://www.mathworks.fr/fr/help/matlab/ref/bar3.html
Upvotes: 11