create a matrix from a matrix x=[-2 -1 0 1 2]; which follow quadratic equations

1 visualización (últimos 30 días)
Hi everyone, i want to create a matrix from this matrix x=[-2 -1 0 1 2] in such a way that resultant matrix is [ (-2^2),(-2^1),(-2^0); (-1^2),(-1^1),(-1^0); (0^2),(0^1),(0^0); (1^2),(1^1),(1^0); (2^2),2^1),(2^0) ]

Respuesta aceptada

Alexandra Harkai
Alexandra Harkai el 30 de Nov. de 2016
x = [-2:2];
y = [2:-1:0];
bsxfun(@power, x', y)
  3 comentarios

Iniciar sesión para comentar.

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 30 de Nov. de 2016
Editada: Andrei Bobrov el 30 de Nov. de 2016
x = [-2 -1 0 1 2];
out = x(:).^(2:-1:0); % for R2016b

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by