How to change the first row of a matrix to be the same as an already programmed vector?

5 次查看(过去 30 天)
So I have vector x
x= 2:4:18
I have the matrix M
M= magic(5)
M=
17 24 18 8 15
23 5 7 2 16
4 6 13 20 6
10 12 19 21 3
11 14 25 2 9
I want the first row of M to be equal to x I write
M(1,:)=x
but I get the error "The expression to the left of the equals sign is not a valid target for an assignment."
  1 个评论
Stephen23
Stephen23 2017-1-29
It works for me:
>> M = magic(5)
M =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> x = 2:4:18
x =
2 6 10 14 18
>> M(1,:) = x
M =
2 6 10 14 18
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by