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

2 次查看(过去 30 天)
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
Duncan Po 2021-6-4
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
  3 个评论
Duncan Po
Duncan Po 2021-6-4
It can work for any real number if you give it a non-integer increment:
>> [x,y] = meshgrid(1:0.1:5,1:0.1:5); % 0.1 increment
>> t = table(x(end,:)',y(end,:)', 'VariableNames', {'x','y'});
>> head(t)
ans =
8×2 table
x y
___ _
1 5
1.1 5
1.2 5
1.3 5
1.4 5
1.5 5
1.6 5
1.7 5

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by