How to change the first row of a matrix to be the same as an already programmed vector?
7 次查看(过去 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
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 Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!