matrix operatios to convert two vectors into a matrix

1 次查看(过去 30 天)
Hello, is it possible to obtain a matrix as follows. X and Y are the input vectors required to change into a matrix..
X=[2 Y=[5 3 1 2 4]-1*5 vector
4
5
3
1]-5*1 vector
both the vectors have the index values as elements....now i want to have a 5*5 matrix which is as follows
Z= (2,5) (2,3) (2,1) (2,2) (2,4)
(4,5) (4,3) (4,1) (4,2) (4,4)
(5,5) (5,3) (5,1) (5,2) (5,4)
(3,5) (3,3) (3,1) (3,2) (3,4)
(1,5) (1,3) (1,1) (1,2) (1,4)
Z-5*5 matrix
is it possible to obtain a matrix like this using matlab...pls help....i have no idea how to do this....thanks in advance...
  2 个评论
Matt J
Matt J 2014-8-20
Your Z is not a matrix because its entries are not scalars. There is no MATLAB data type that will efficiently hold large arrays of non-scalar data. You should look for an approach which doesn't require X and Y to be combined into a single array.
Adam
Adam 2014-8-20
Despite my potential solution below I would agree with Matt J on the whole though on considering whether you really need this in one matrix.
Possibly you could simply work with the intermediate meshgrid results.
Cell arrays are good for allowing you to store arbitrary things in a matrix form, but their efficiency is not great if you need speed and large amounts of data.

请先登录,再进行评论。

采纳的回答

Adam
Adam 2014-8-20
编辑:Adam 2014-8-20
[Ygrid, Xgrid] = meshgrid( Y, X );
Z = arrayfun( @(X,Y) [X Y], Xgrid, Ygrid, 'UniformOutput', false );
should give you a 5*5 cell array where each cell is the pair you describe.

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by