MATLAB 3D drawing Summary

Source: Internet
Author: User

1. Draw a 3D graph of the function, for example, Z (x, y) = 2 * X. * exp (-X. ^ 2-y. ^ 2) + 1;

Close all; [x, y] = meshgrid (-2: 0.. 5:2); % generate coordinate axis Z = 2 * X. * exp (-X. ^ 2-y. ^ 2) + 1; % Z is X, function % of Y % num = 0; num = num + 1; subplot (2, 3, num); plot3 (x, y, z); axis ([-3 3 3-3 0 2]); % limit the display range xlabel ('x axis '); % x axis coordinate ylabel ('y axis'); % Y axis coordinate zlabel ('z axis '); % Z axis coordinate title ('HTTP: // blog.csdn.net/nuptboyzhb/ figure (1 )'); % title % % num = num + 1; subplot (2, 3, num); mesh (x, y, z); axis ([-3 3-3 3 0 2]); % limit the display range xlabel ('x axis '); % x axis coordinate ylabel ('y axis'); % Y axis coordinate zlabel ('z axis '); % Z axis coordinate title ('HTTP: // blog.csdn.net/nuptboyzhb/ figure (2 )'); % title % % num = num + 1; subplot (2, 3, num); meshc (x, y, z); axis ([-3 3-3 3 0 2]); % limit the display range xlabel ('x axis '); % x axis coordinate ylabel ('y axis'); % Y axis coordinate zlabel ('z axis '); % Z axis coordinate title ('HTTP: // blog.csdn.net/nuptboyzhb/ figure (3 )'); % title % % num = num + 1; subplot (2, 3, num); SURF (x, y, z); axis ([-3 3-3 3 0 2]); % limit the display range xlabel ('x axis '); % x axis coordinate ylabel ('y axis'); % Y axis coordinate zlabel ('z axis '); % Z axis coordinate title ('HTTP: // blog.csdn.net/nuptboyzhb/ figure (4 )'); % title % % num = num + 1; subplot (2, 3, num); meshz (x, y, z); axis ([-3 3-3 3 0 2]); % limit the display range xlabel ('x axis '); % x axis coordinate ylabel ('y axis'); % Y axis coordinate zlabel ('z axis '); % Z axis coordinate title ('HTTP: // blog.csdn.net/nuptboyzhb/ figure (5 )'); % title % % num = num + 1; subplot (2, 3, num); SURF (x, y, z); Hold on; stem3 (X, Y, Z, 'R '); % draw a vertical axis ([-3 3-3 3 0 2]); % limit the display range xlabel ('x' axis '); % x axis coordinate ylabel ('y axis '); % Y axis coordinate zlabel ('z axis'); % Z axis coordinate title ('HTTP: // blog.csdn.net/nuptboyzhb/ figure (6 )'); % title

 

 

2. Draw a three-dimensional map of the matrix

CLC; clear all; close all; X = [0 1 2 3 4 5 6 7 8 9]; y = [0 1 2 3 4 5 6 7 8 9]; for I = 1: 1: length (x) for j = 1: 1: length (y) Z (I, j) = Mod (I * j * rand (1 ), 9 ); endend % % num = 0; num = num + 1; subplot (2, 3, num); plot3 (x, y, z); axis ([0 9 0 9 0 9]); % limit the display range xlabel ('x axis '); % x axis coordinate ylabel ('y axis'); % Y axis coordinate zlabel ('z axis '); % Z axis coordinate title ('HTTP: // blog.csdn.net/nuptboyzhb/ figure (1 )'); % title % % num = num + 1; subplot (2, 3, num); mesh (x, y, z); axis ([0 9 0 9 0 9]); % limit the display range xlabel ('x axis '); % x axis coordinate ylabel ('y axis'); % Y axis coordinate zlabel ('z axis '); % Z axis coordinate title ('HTTP: // blog.csdn.net/nuptboyzhb/ figure (2 )'); % title % % num = num + 1; subplot (2, 3, num); meshc (x, y, z); axis ([0 9 0 9 0 9]); % limit the display range xlabel ('x axis '); % x axis coordinate ylabel ('y axis'); % Y axis coordinate zlabel ('z axis '); % Z axis coordinate title ('HTTP: // blog.csdn.net/nuptboyzhb/ figure (3 )'); % title % % num = num + 1; subplot (2, 3, num); SURF (x, y, z); axis ([0 9 0 9 0 9]); % limit the display range xlabel ('x axis '); % x axis coordinate ylabel ('y axis'); % Y axis coordinate zlabel ('z axis '); % Z axis coordinate title ('HTTP: // blog.csdn.net/nuptboyzhb/ figure (4 )'); % title % % num = num + 1; subplot (2, 3, num); meshz (x, y, z); axis ([0 9 0 9 0 9]); % limit the display range xlabel ('x axis '); % x axis coordinate ylabel ('y axis'); % Y axis coordinate zlabel ('z axis '); % Z axis coordinate title ('HTTP: // blog.csdn.net/nuptboyzhb/ figure (5 )'); % title % % num = num + 1; subplot (2, 3, num); SURF (x, y, z); Hold on; stem3 (X, Y, Z, 'R '); % draw a vertical axis ([0 9 0 9 0 9]); % limit the display range xlabel ('x axis '); % x axis coordinate ylabel ('y axis '); % Y axis coordinate zlabel ('z axis '); % Z axis coordinate title ('HTTP: // blog.csdn.net/nuptboyzhb/ figure (6)'); % title

 

 

3. color depth of the matrix

A function compiled by myself: graycolor. m

% Filename: graycolor. M % Zheng Haibo 2013-01-31% success! % Parameter: newbuf must make the two-dimensional array or Matrix Function graycolor (newbuf); min_n = min (newbuf); max_n = max (newbuf); newbuf = newbuf. /(max_n-min_n) * 255; [m n] = size (newbuf); for I = 1: 1: m for j = 1: 1: n r (I, j) = graycolorr (newbuf (I, j); G (I, j) = graycolorg (newbuf (I, j); B (I, j) = graycolorb (newbuf (I, j); endendimg (1: 1: M, 1: 1: N, 1) = r (1: M, 1: N ); IMG (1: 1: M, 1: 1: N, 2) = g (1: M, 1: N); IMG (1: 1: M, 1: 1: n, 3) = B (1: M, 1: N); imshow (uint8 (IMG); function r = graycolorr (Gray) r = 0; if gray> = 170 r = 255; endif gray> = 128 & gray <= 170 r = 255/42 * (Gray-128); endreturn; function g = graycolorg (Gray) G = 0; if Gray> = 84 & gray <= 170g = 255; endif gray <= 84g = 255/84 * gray; endif gray> = 170 & gray <= 255g = 255/85 * (255-gray); endreturn; function B = graycolorb (Gray) B = 0; if gray <= 84 B = 255; endif gray> = 84 & gray <= 128 B = 255/44 * (128-gray); endreturn;

 

Function call:

[X, y] = meshgrid (-2: 0.. 0); % generate coordinate axis Z = 2 * X. * exp (-X. ^ 2-y. ^ 2) + 1; % Z is X, the function graycolor (z) of Y; Title ('HTTP: // blog.csdn.net/nuptboyzhb/'); % title

In addition, we will provide a more detailed introduction to the file \ MATLAB 2009a \ toolbox \ MATLAB \ demos \ graf3d. M. The interface is as follows:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.