Inserting a column vector as a column in a new matrix.

1 visualización (últimos 30 días)
Hello,
I have a column vector (say X). And I want to make that vector as a column in my new matrix, i.e., the first column is only 1s, second column is X and third column is X^2.
Any idea as how to do it?
Thanks !!!

Respuesta aceptada

Sachin Ganjare
Sachin Ganjare el 17 de Oct. de 2012
new_matrix = [1s_col X X^2]

Más respuestas (3)

Matt J
Matt J el 17 de Oct. de 2012
I suspect that this is what you really want:
vander(X).'
or
bsxfun(@power,X(:),[0,1,2]);

Swasti Khuntia
Swasti Khuntia el 17 de Oct. de 2012
Thanks a lot Sachin and Matt !! Both of them works out for me. Since Sachin answered it first, I had to accept it :)

Matt J
Matt J el 17 de Oct. de 2012
I'm also going to hazard a guess that the matrix you're trying to create is meant so that you can fit a quadratic polynomial.
If so, you should probably be using POLYFIT instead, which is more stable.

Categorías

Más información sobre Logical 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