Borrar filtros
Borrar filtros

assigning values to a matrix

155 visualizaciones (últimos 30 días)
William Hou
William Hou el 6 de En. de 2021
Comentada: Walter Roberson el 6 de En. de 2021
so I have this matrix,and I want everything on the 4th row to become 4s.
a=zeros(10,10)
I tried a(30,40)=4, but that altered the column instead of the rows, and also changed that highlighted position to 4, which I don't want. changing the range doesn't seen to do much to solve that. How can I assign values to the rows instead of the columns?
  1 comentario
Walter Roberson
Walter Roberson el 6 de En. de 2021
I think you did a(30:40)=4 to get that result.

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 6 de En. de 2021
This:
a(4,:) = 4
produces:
a =
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
4 4 4 4 4 4 4 4 4 4
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
.
  1 comentario
Walter Roberson
Walter Roberson el 6 de En. de 2021
a=zeros(10,10)
a = 10×10
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
a(4:10:end) = 4
a = 10×10
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by