How to create an array

5 visualizaciones (últimos 30 días)
JRC
JRC el 19 de Jul. de 2017
Comentada: Star Strider el 19 de Jul. de 2017
How to create an array
A = [0 0 0 0; 1 1 1 1; 2 2 2 2; 3 3 3 3; 4 4 4 4]
using the command "for" or other?

Respuesta aceptada

Star Strider
Star Strider el 19 de Jul. de 2017
Use the repmat function:
A = repmat(0:4, 4, 1)';
A =
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
  2 comentarios
JRC
JRC el 19 de Jul. de 2017
Perfect Star Strider!
I didn´t know the command "repmat".
Thank you.
Star Strider
Star Strider el 19 de Jul. de 2017
As always, my pleasure!
Another option for your particular problem is to use element-wise vector multiplication:
A = [0:4]'.*ones(1,4);
See the documentation on Array vs. Matrix Operations (link) for details.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices 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