undisired grid size with meshgrid

9 views (last 30 days)
Yu Li
Yu Li on 16 Jan 2018
Answered: Image Analyst on 16 Jan 2018
Hi: I have a three 1-D constant space matrix, and I want to use them to generate a 3D space mesh.
the size of each is x: 1*532, y: 1*357, z:1*1072.
after I used the meshgrid:
[X,Y,Z]=meshgrid(x,y,z);
the size of X, Y, Z are : 357*532*1072. but I think they should be: 532*357*1072.
is there any problem with my operation?
Thanks! Li

Accepted Answer

Image Analyst
Image Analyst on 16 Jan 2018
Remember y is rows and thus will be the first index. So it returns an array 357*532*1072 which is 357 rows by 532 columns by 1072 slices. Your y is 357 so that's why it's first and you have 357 rows. When the workspace says n*m*s, the first number is the number of rows, which is y, not x.
x = 1:532; % Columns
y = 1 : 357; % Rows
z = 1 : 1072; % Slices
[X,Y,Z]=meshgrid(x, y, z);
[rows, columns, slices] = size(X)

More Answers (1)

Matt J
Matt J on 16 Jan 2018
Use ndgrid instead
[X,Y,Z]=ndgrid(x,y,z);

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!