필터 지우기
필터 지우기

matrix operatios to convert two vectors into a matrix

조회 수: 1 (최근 30일)
Abirami
Abirami 2014년 8월 20일
댓글: Adam 2014년 8월 20일
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에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by