필터 지우기
필터 지우기

how can i get a horzenital vector?

조회 수: 1 (최근 30일)
Aseel H
Aseel H 2011년 9월 14일
X = [2 1 5 1
5 4 8 1
1 4 5 7];
if i use X1 = X(:);
the output is X1=[2
5
1
1
4
4
5
8
5
1
1
7]
but i wante the out put is X1 =[2 1 5 1 5 4 8 1 1 4 5 7];
thank you very much

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 9월 14일
X1 = reshape(X',1,[])
  댓글 수: 2
Andrei Bobrov
Andrei Bobrov 2011년 9월 14일
My typo! Corrected...
Thanks Fangjun!
Jan
Jan 2011년 9월 14일
@Fangjun: Without the transpose, you get X1 = [2,5,1,...], but Amal wants [2,1,5,...] - the data in row order.

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

추가 답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 9월 14일
X1=X';
X1=X1(:);

Daniel Shub
Daniel Shub 2011년 9월 14일
If there is any chance that you matrix will have complex numbers you need to be careful with the difference between ' (ctranspose) and .' (transpose). To be clear I might go with:
X1 = transpose(X(:));
I do not know if there is a performance difference between ctranspose and transpose for real matrices.
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2011년 9월 14일
There is not. Though there was a bug with ctranspose in the original release of R2009b.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by