Borrar filtros
Borrar filtros

How to Multiply a number to a row of matrix

29 visualizaciones (últimos 30 días)
Tran Thien
Tran Thien el 23 de Dic. de 2017
Comentada: akhil soni el 3 de Sept. de 2020
For example i have matrix
A = [ 1 2 3 ; 3 4 5]
I want to multiply 2 to the 2nd row of the matrix so i got
A = [ 1 2 3 ; 6 8 10]

Respuesta aceptada

Star Strider
Star Strider el 23 de Dic. de 2017
Use bsxfun to multiply the first row by 1 (so it remains the same), and the second row by 2:
A = [ 1 2 3 ; 3 4 5];
A = bsxfun(@times, A, [1; 2])
A =
1 2 3
6 8 10
  3 comentarios
Star Strider
Star Strider el 23 de Dic. de 2017
As always, my pleasure!
akhil soni
akhil soni el 3 de Sept. de 2020
Thanks ...it helped me a lot:))

Iniciar sesión para comentar.

Más respuestas (1)

David Wilson
David Wilson el 26 de Dic. de 2017
or if you have a recent version of Matlab, then one can avoid the cryptic bxfun with
>> A.*[1;2]

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by