Borrar filtros
Borrar filtros

how to write a very concise expression for matrix power

1 visualización (últimos 30 días)
Xin
Xin el 12 de Oct. de 2016
Comentada: dpb el 12 de Oct. de 2016
I have a row vector, e.g. [1,2,3,4], and I want to put, say 3 different power [1;2;3] to create a matrix as follow:
[1,2,3,4]?^[1;2;3] = [1,2,3,4 ; 1,4,9,16 ; 1,8,27,64].
Anyone knows how to get it without using a loop. Many thanks!

Respuesta aceptada

Matt J
Matt J el 12 de Oct. de 2016
As of R2016b, you can just do this
[1;2;3] .^ [1,2,3,4]
Otherwise, use bsxfun()
  4 comentarios
Xin
Xin el 12 de Oct. de 2016
Nice, bsxfun does work. Thank you so much!
dpb
dpb el 12 de Oct. de 2016
Then please ACCEPT the answer...

Iniciar sesión para comentar.

Más respuestas (1)

dpb
dpb el 12 de Oct. de 2016
>> bsxfun(@power,[1:4],[1:3].')
ans =
1 2 3 4
1 4 9 16
1 8 27 64
>>

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