Resizing a vector to a matrix

I have a vector which is of size 1x3. I want to resize to 13x3 matrix..is it possible to do it? how can i proceed

Respuestas (1)

Stephen23
Stephen23 el 9 de Dic. de 2015
Editada: Stephen23 el 9 de Dic. de 2015

0 votos

It depends on how you want to resize the vector. If you simply want to replicate those values into every row of the final matrix, then try either of these methods:
>> X = [1,2,3]
X =
1 2 3
>> repmat(X,5,1)
ans =
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
>> X(ones(1,5),:)
ans =
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
Note that I created 5x3 matrices, but I am sure that you can figure out how to create 13x3 matrices.

3 comentarios

Ramanan Viswanathan
Ramanan Viswanathan el 9 de Dic. de 2015
hi..thanks but i dont want to repeat values....My superviser suggested me to first measure the size of the vector, take a for loop and change the dimensions of the vector.. thats where i am stuck and i have no idea..can u help me out
James Tursa
James Tursa el 9 de Dic. de 2015
@Ramanan: You need to be more specific. As Stephen has already stated, you need to tell us how you want this to be done. Maybe give us an example.
Stephen23
Stephen23 el 9 de Dic. de 2015
Here is another easy way to resize a vector, by adding a value and filling the rest with zeros:
>> X = [1,2,3]
X =
1 2 3
>> X(5,1) = 0
X =
1 2 3
0 0 0
0 0 0
0 0 0
0 0 0
I repeat my original comment: how do you want your matrix expanded (if not with replicated values)?

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 9 de Dic. de 2015

Comentada:

el 9 de Dic. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by