Use of ":"operator in matlab?

조회 수: 1 (최근 30일)
ABTJ
ABTJ 2020년 6월 21일
편집: Stephen23 2020년 6월 23일
Let say i have a matrix; x=[2 3;4 5] % 2 rows 2 columns
then i enter command , x(:)=[2;3;4;5] % 4 rows 1 column
What is happening here?
Is there any possiblity that i get 1 row 4 columns?If yes,how?

채택된 답변

madhan ravi
madhan ravi 2020년 6월 21일
(:) forces the matrix to a column vector, all you need is
reshape(matrix, 1, [])
  댓글 수: 2
Stephen23
Stephen23 2020년 6월 23일
편집: Stephen23 2020년 6월 23일
"(:) forces the matrix to a column vector"
Only when used in an expression or the RHS of an assignment. On the LHS it simply refers to all elements of the array (in linear index order) and does not change the size or shape of the LHS array at all. See:
madhan ravi
madhan ravi 2020년 6월 23일
편집: madhan ravi 2020년 6월 23일
“Only when used on the RHS of an assignment”
Exactly what the OP was asking and I was referring too. Was expecting your comment a bit earlier though ;). But thank you for explaining the details.

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

추가 답변 (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