필터 지우기
필터 지우기

Adjusting the dimensions of input argument

조회 수: 5 (최근 30일)
Sordin
Sordin 2019년 5월 6일
편집: Adam Danz 2019년 5월 6일
I have written a function which takes in a row vector A as the input. If A is a column vector, I want the program to convert it into a row vector (i.e., replace it by its transpose). This can be achieved using an if statement:
if size(A,1) ~= 1
A = A';
end
Is there a shorter way of impelmenting this that does not require an if statement?
Any suggestions would be greatly appreciated.

채택된 답변

Stephen23
Stephen23 2019년 5월 6일

추가 답변 (1개)

Adam Danz
Adam Danz 2019년 5월 6일
편집: Adam Danz 2019년 5월 6일
A = reshape(A,1,[]);
The above will transpose a column vector or will leave a row vector as is.
A quick note on the use of " ' " versus " .' " If your merely transposing a matrix, use the latter. The prior will also negate the sign of an imaginary parts of complex elements (if any).

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by