Matlab Meshgrid function Generation two-dimensional mesh matrix example explanation

Source: Internet
Author: User

usage is [x Y]=meshgrid (A, b);

Meshgrid


Where A and B are all one-dimensional arrays

Give some examples

1. A=[1 2 3] b=[2 3 4]

Then the resulting matrix X and y are all 3*3 matrices.

where each row of the x matrix is [1 2 3], the number of rows is determined by the length of the array b

Each column of the Y-matrix is [2 3 4], and the number of columns is determined by the length of the array a

>> [x Y]=meshgrid (A, B)
x =
1 2 3
1 2 3
1 2 3
y =
2 2 2
3 3 3
4 4 4

2.a=[1 2 3] b=[2 3]

The resulting x and y are all 3*2 matrices.

>> [x Y]=meshgrid (A, B)
x =
1 2 3
1 2 3
y =
2 2 2
3 3 3

where each row of the x matrix is [1 2 3], the number of rows is determined by the length of the array b

Each column of the y Matrix is [2 3], and the number of columns is determined by the length of the array A.

3.a=[1 2] b= [2 3 4]

The resulting matrices are all 2*3 dimensions.

>> [x Y]=meshgrid (A, B)
x =
1 2
1 2
1 2
y =
2 2
3 3
4 4

where each row of the x matrix is 1 2, the number of rows is determined by the length of the array B.

Each column of the Y-matrix is 2 3 4, and the number of columns is determined by the length of the array a



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.