1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>MESHGRID Generate Grid Mesh For Plots
</TITLE>
</HEAD>
<BODY>
<H2>MESHGRID Generate Grid Mesh For Plots
</H2>
<P>
Section: <A HREF=sec_array.html> Array Generation and Manipulations </A>
<H3>Usage</H3>
The <code>meshgrid</code> function generates arrays that can be used for the
generation of surface plots. The syntax is one of
<PRE>
[X,Y] = meshgrid(x)
[X,Y] = meshgrid(x,y)
[X,Y,Z] = meshgrid(x,y,z)
</PRE>
<P>
where <code>x,y,z</code> are vectors, and <code>X,Y,Z</code> are matrices. In the first
case <code>[X,Y] = meshgrid(x)</code>, the rows of <code>X</code> and the columns of <code>Y</code>
contain copies of the vector <code>x</code>. In the second case
<code>[X,Y] = meshgrid(x,y)</code>, the rows of <code>X</code> contain copies of <code>x</code>, and
the columns of <code>Y</code> contain copies of <code>y</code>. In the third case, each
input is copied along the row, column or slice direction of the
corresponding output variable.
<H3>Example</H3>
In the first example:
<PRE>
--> [X,Y] = meshgrid(-2:.4:2)
X =
Columns 1 to 8
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 0.0000 0.4000 0.8000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 0.0000 0.4000 0.8000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 0.0000 0.4000 0.8000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 0.0000 0.4000 0.8000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 0.0000 0.4000 0.8000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 0.0000 0.4000 0.8000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 0.0000 0.4000 0.8000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 0.0000 0.4000 0.8000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 0.0000 0.4000 0.8000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 0.0000 0.4000 0.8000
-2.0000 -1.6000 -1.2000 -0.8000 -0.4000 0.0000 0.4000 0.8000
Columns 9 to 11
1.2000 1.6000 2.0000
1.2000 1.6000 2.0000
1.2000 1.6000 2.0000
1.2000 1.6000 2.0000
1.2000 1.6000 2.0000
1.2000 1.6000 2.0000
1.2000 1.6000 2.0000
1.2000 1.6000 2.0000
1.2000 1.6000 2.0000
1.2000 1.6000 2.0000
1.2000 1.6000 2.0000
Y =
Columns 1 to 8
-2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000 -2.0000
-1.6000 -1.6000 -1.6000 -1.6000 -1.6000 -1.6000 -1.6000 -1.6000
-1.2000 -1.2000 -1.2000 -1.2000 -1.2000 -1.2000 -1.2000 -1.2000
-0.8000 -0.8000 -0.8000 -0.8000 -0.8000 -0.8000 -0.8000 -0.8000
-0.4000 -0.4000 -0.4000 -0.4000 -0.4000 -0.4000 -0.4000 -0.4000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.4000 0.4000 0.4000 0.4000 0.4000 0.4000 0.4000 0.4000
0.8000 0.8000 0.8000 0.8000 0.8000 0.8000 0.8000 0.8000
1.2000 1.2000 1.2000 1.2000 1.2000 1.2000 1.2000 1.2000
1.6000 1.6000 1.6000 1.6000 1.6000 1.6000 1.6000 1.6000
2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000
Columns 9 to 11
-2.0000 -2.0000 -2.0000
-1.6000 -1.6000 -1.6000
-1.2000 -1.2000 -1.2000
-0.8000 -0.8000 -0.8000
-0.4000 -0.4000 -0.4000
0.0000 0.0000 0.0000
0.4000 0.4000 0.4000
0.8000 0.8000 0.8000
1.2000 1.2000 1.2000
1.6000 1.6000 1.6000
2.0000 2.0000 2.0000
</PRE>
<P>
Next, we use different vectors for <code>X</code> and for <code>Y</code>:
<PRE>
--> [X,Y] = meshgrid([1,2,3,4],[6,7,8])
X =
1 2 3 4
1 2 3 4
1 2 3 4
Y =
6 6 6 6
7 7 7 7
8 8 8 8
</PRE>
<P>
</BODY>
</HTML>
|