Assigning the Values to 2-D Matrix which has 2 Elements in Each Point

1 次查看(过去 30 天)
Hello, I am trying to assign the values to a matrix. This matrix is a 3x3 matrix but every point has 2 elements, which are the coordinates of a point, in other words x and y values.
For example I want this matrix to be in the form of:
[0 500] [100 500] [200 500]
[0 250] [100 250] [200 250]
[0 0] [100 0] [200 0]
The Y values are 0, 250, 500 and the X values are 0, 100, 200 respectively. I tried to assign values by using for loop but I could not achieve the assignment of 2nd element. Can you help me? Thank you.
  16 个评论
tinkyminky93
tinkyminky93 2022-3-29
I think this is not the correct solution, complex number representation should not be used as coordinates sir. Thanks for your effort. At least I understand some concepts.
Torsten
Torsten 2022-3-29
I just wanted to say that - although complex numbers are in principle tuples of real numbers - they can be assigned to matrix elements. Also, rules how to add, subtract, multiply and divide such matrices are already implemented.
For your case, when you work with cell arrays - these rules are not yet available and you had to define and implement them on your own.

请先登录,再进行评论。

回答(1 个)

David Hill
David Hill 2022-3-29
Sounds like you need two matrices. A x matrix and a y matrix.
[x,y]=meshgrid(0:100:200,0:250:500);
  4 个评论
Torsten
Torsten 2022-3-29
编辑:Torsten 2022-3-29
I already gave you the answer above.
Everywhere where you would use A(i,j), you write [x(i,j),y(i,j)].

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by