# creating table of finely spaced xy points that represent a box corner

1 view (last 30 days)
Jon Conger on 2 Jun 2021
Commented: Jon Conger on 4 Jun 2021
I'd like operate on an XY table of values that represents one quadrant of a box, but rather than just defining the vertical and horizontal extremes I need a certain resolution of points along the lines of this box because after my math operations it will no longer look like a box. An example is below, but in reality I'll probably have more than 100 points so I can't manually type each one in.
I was thinking of something like this to draw the upper horizontal line:
%upper line
xmax = 5
ymax = 5
ux = [0:1:xmax]
uy = [ymax]
table (ux,uy)
But it doesn't create an equal number of Y values as X. Once I solve that problem my plan was to do the same for the veritical line, and then combine them.
Or is there an easier way where I can define a 2xN array?
An example of the ultimate table is below (but again, I need it to be adjustable and have far finer resolution):
x y
0 5
1 5
2 5
3 5
4 5
5 5
5 5
5 4
5 3
5 2
5 1
5 0

Duncan Po on 4 Jun 2021
meshgrid may be the function you are looking for. For example,
>> [x,y] = meshgrid(1:5,1:5)
x =
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
y =
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
The horizontal line will then just be the last row.
>> t = table(x(end,:)',y(end,:)', 'VariableNames', {'x','y'})
t =
5×2 table
x y
_ _
1 5
2 5
3 5
4 5
5 5
Jon Conger on 4 Jun 2021
Ah, got it. Thanks again!

### Community Treasure Hunt

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

Start Hunting!

Translated by