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

7 Ansichten (letzte 30 Tage)
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 Kommentar
Stephen23
Stephen23 am 29 Jan. 2017
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

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by