MATLAB 3D data plotting

Source: Internet
Author: User
Zookeeper

3D data draw lip image mainly consists of two parts, one is the lip in the X-Y plane raster, one is according to the corresponding Z axis coloring. It mainly uses meshgrid, surf, and shading in MATLAB.

1. Use meshgrid to generate a grid

Meshgrid (x, y) uses the vector X and vector y to generate the raster data point matrices X and Y required for drawing the image. This command generates raster data by using the vector X as a row vector of matrix X, and copying the vector X for length (y) times to form the X matrix of the raster data point. Similarly, use Vector y as a column vector of matrix Y, and copy the vector y for length (x) times to form the y matrix of the raster data point.



The figure shows that the data grid is generated on the X and Y planes.

However, all Rectangular areas are generated using meshgrid, that is, the bottom layer is a rectangle Based on the Z axis coloring, and the regular image is drawn. If the irregular image is drawn, the linspace function is used, the linspace function is in the form of linspace (x1, x2, n). With X1 as the starting element and X2 as the ending element, a column vector of n elements with equal spacing is generated, in fact, the entire generation process is completed through interpolation. N represents the number of data inserted between X1 and X2. The following figure shows how to draw a picture in this experiment:

             [X,Y] = meshgrid(linspace(min(aa),max(a),300),linspace(min(b1),max(b),300));
2. Draw a 3D Surface with surf

After the raster of X and Y is painted in the previous step, color the grid according to the Z axis to observe the effect of three dimensions. The format of surf is surf (x, y, z), where X and Y are the raster data generated in the previous step, and Z is the Z axis data corresponding to X and Y, coloring based on this.

However, colormap and shading are required to paint any color.

So the code is as follows:

                          surf(X,Y,Z);                          shading interp;                          colormap gray;
However, the above question is not mentioned. How can we map the Z and X and Y data? In this case, we need to use:
                  F = TriScatteredInterp(a,b,c);                  Z = F(X,Y);

Triscatteredinterp maps the data of X, Y, and Z.

3. Coordinate Axis settings

In this experiment, the Axis settings mainly use two features: saving means not saving the axis, and setting the axis range. The Code is as follows:

Axis off % causes axis to disappear % The following is the set axis range midx = (max (A) + min (AA)/2; midy = (max (bb) + min (B1)/2; midz = (max (c) + min (c)/2; axis ([midx-0.03, midx + 0.03, midy-0.022, midy + 0.022, midz-0.015, midz + 0.015]);

4 View

After the image is drawn, surf does not display a front image of the lip, but an image with a viewpoint of-37.5 ° and an elevation of 30 °. By rotating This 3D image, you can see the various perspectives of this lip. The first glance is the default value for the viewer. You can use View (AZ, El) to define the angle of view, AZ to indicate the azimuth, El

The elevation of angle.

View (2) % projected to xy plane

5. Save print

After finishing the image, you need to save the image. Use print to save the image. You can use '-r9' to set the size of the saved image. The Code is as follows:

                 print(gcf,'-djpeg','-r9',strcat(savepath,imageName));

However, the saved image will save a large number of blank areas around the image, so you can use the following code to remove the blank area:

         set(gcf, 'PaperPositionMode', 'manual');         set(gcf, 'PaperUnits', 'points');         axis image;         set(gca,'position',[0,0,1,1]);         set(gcf, 'PaperPosition', [0 0 510 510]);         set(gcf,'visible','off');

Note: Use hold on and hold off for small details


The references are as follows:

Http://wenku.baidu.com/link? Url = Response

Http://blog.macro2.org/2010-09/%e4%b8%8d%e8%a7%84%e5%88%99%e6%a0%b7%e6%9c%ac%e7%82%b9%e7%bb%98%e5%88%b6%e6%9b%b2%e9%9d%a2%e5%9b%be%e5%bd%a2-griddata%e7%af%87.html

Http://wenku.baidu.com/link? Url = Response

Http://hi.baidu.com/skyliujk/item/68c10d4785adc5eebcf45148

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.