How to create a mesh grid point in MatLab - meshgrid -- MatLab
How to create a mesh grid point in MatLab - meshgrid -- MatLab
Here is my code and results about meshgrid.
%meshgrid_example
clear
clc
x = 1:3;
y = 1:5;
[X,Y] = meshgrid(x,y)
%{
X =
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
Y =
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
%}
"1\n"
x = 1:3;
y = 1:5;
[X,Y]=meshgrid(x)
%similar to
%[X,Y]=meshgrid(x,x)
%{
X =
1 2 3
1 2 3
1 2 3
Y =
1 1 1
2 2 2
3 3 3
%}
"2\n"
x = 1:3;
y = 1:5;
z = 1:4;
[X,Y,Z]=meshgrid(x,y,z)
%{
X(:,:,1) =
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
X(:,:,2) =
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
X(:,:,3) =
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
X(:,:,4) =
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
Y(:,:,1) =
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
Y(:,:,2) =
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
Y(:,:,3) =
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
Y(:,:,4) =
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
Z(:,:,1) =
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
Z(:,:,2) =
2 2 2
2 2 2
2 2 2
2 2 2
2 2 2
Z(:,:,3) =
3 3 3
3 3 3
3 3 3
3 3 3
3 3 3
Z(:,:,4) =
4 4 4
4 4 4
4 4 4
4 4 4
4 4 4
%}
"3\n"
x = 1:3;
y = 1:5;
z = 1:4;
[X,Y,Z]=meshgrid(x)
%similar to
%[X,Y,Z]=meshgrid(x,x,x)
%{
X(:,:,1) =
1 2 3
1 2 3
1 2 3
X(:,:,2) =
1 2 3
1 2 3
1 2 3
X(:,:,3) =
1 2 3
1 2 3
1 2 3
Y(:,:,1) =
1 1 1
2 2 2
3 3 3
Y(:,:,2) =
1 1 1
2 2 2
3 3 3
Y(:,:,3) =
1 1 1
2 2 2
3 3 3
Z(:,:,1) =
1 1 1
1 1 1
1 1 1
Z(:,:,2) =
2 2 2
2 2 2
2 2 2
Z(:,:,3) =
3 3 3
3 3 3
3 3 3
%}
"4\n"
syntax
(1)[X,Y]=meshgrid(x,y)
X will be
X* length(Y)
Y will be
Y*length(X)'
(2)[X,Y]=meshgrid(x)
will be considered as
[X,Y]=meshgrid(x,y)
(3)[X,Y,Z]=meshgrid(x,y,z)
X will be
X=meshgrid(x,y)*Z
Y will be
Y=meshgrid(x,y)*Z
Z will be [X,Y]=meshgrid(x,y)
Z=meshgrid(y,z)**length(Z)
where
vec1 * n means that duplicate vec1 n times and concatenate it at buttom.
M1 * n means that duplicate M1 n times and concatenate it at buttom.
M1 ** n means that for each row vec1 , vec1*n and add it into M2 where M2 is an empty matrix at first.
In above code, We can know a few things.
(1)
N-D-plots and
dimension of output in each output argument will be sometimes determined by number of out arguments,
or sometimes determined by number of input arguments.
(2)Number of output arguments can be either 2 or 3.
(3)Number of input arguments can be either 1 or N-D-plots.
(4)When number of output argument is 2 , it determines that 2-D-plot, so number of input arguments can be either 1 or 2.
In this case, if number of input arguments is 1 (e.g. if you just throw 'x' as input argument
i.e. call meshgrid(x)).
The MatLab will consider meshgrid (x,x).
(5)When number of output argument is 3 , it determines that 3-D-plot, so number of input arguments can be either 1 or 3.
In this case, if number of input arguments is 1 (e.g. if you just throw 'x' as input argument i.e.
call meshgrid(x)).
The MatLab will consider meshgrid (x,x,x).
more details on:
Comments
Post a Comment