adding ones at the end of an array

can you help me to add ones at the end of 2*3 matrix to change it to 5*3 matrix. i want not zeros .

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 1 de Mzo. de 2019
Editada: KALYAN ACHARJYA el 1 de Mzo. de 2019
k=randi(3,3)
k =
3 3 2
3 3 1
3 2 3
>> k=[k;ones(2,3)]
k =
3 3 2
3 3 1
3 2 3
1 1 1
1 1 1
>>

2 comentarios

I'd recommend
k = [k; ones(2, size(k, 2))];
to make it work for k of any size. In general, never hardcode the size of matrices if you get ask matlab for it.
KALYAN ACHARJYA
KALYAN ACHARJYA el 1 de Mzo. de 2019
@Guillaume Thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 1 de Mzo. de 2019

Comentada:

el 1 de Mzo. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by