Writing m*n matrix into single array

I want to write m*n matrix into single array

댓글 수: 4

Say what? An matrix is an array ...
If you want to recast 2D as 1D then there's either reshape or the Matlab idiom using the : operator--
x=x(:); % column vector
will turn any dimension of an array/matrix into a (column) vector. If you want row, then just transpose the result--
x=x(:).'; % row vector
Abdul Gaffar
Abdul Gaffar 2017년 11월 3일
편집: Walter Roberson 2017년 11월 3일
Consider A=[1,1,2;4,3,2;2,3,4]
Now when i use A=A(:), I am getting A=[1,4,2,1,3,3,2,2,4] which is not equal to original A(3*3) matrix
Walter Roberson
Walter Roberson 2017년 11월 3일
Yes? You can reshape(A,3,3) to get back the original ?
We do not understand what you are starting with and what you need to end up with ??
dpb
dpb 2017년 11월 4일
편집: dpb 2017년 11월 5일
All the elements of A(:) are identical to those in the original A; only the shape was changed. The expansion to vector is in column-major order; that is each column is in turn appended to the preceding. This is internal Matlab storage order and an extremely important concept in learning to use the vector facilities within Matlab.
All that occurs is, as Walter notes, a reordering of the apparent shape such that matrix operations can be performed on the matrix according to the laws of matrix algebra or elemental operations on conformant arrays.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 11월 3일

0 개 추천

YourMatrix(:)
would give a column vector containing the same elements, if that is what you want ?

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2017년 11월 3일

편집:

dpb
2017년 11월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by