Use of ":"operator in matlab?

1 次查看(过去 30 天)
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 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by