Borrar filtros
Borrar filtros

How to create a vector of this output?

2 visualizaciones (últimos 30 días)
Kash Costello
Kash Costello el 29 de Nov. de 2018
Comentada: Star Strider el 29 de Nov. de 2018
Hi!
Can anyone tell me how to do this in matlab? I've tried using 3 for loops but I am getting the wrong answer. My range is from -2 to 2.
Here is what I want to get:
... and so on and so forth.
Thanks a lot!

Respuesta aceptada

Star Strider
Star Strider el 29 de Nov. de 2018
Try this:
[X,Y,Z] = ndgrid(-2:2);
Out = [Z(:),Y(:),X(:)]
producing:
Out =
-2 -2 -2
-2 -2 -1
-2 -2 0
-2 -2 1
-2 -2 2
-2 -1 -2
-2 -1 -1
-2 -1 0
-2 -1 1
-2 -1 2
-2 0 -2
-2 0 -1
-2 0 0
-2 0 1
-2 0 2
etc.
  2 comentarios
Kash Costello
Kash Costello el 29 de Nov. de 2018
THANK YOU <3
Star Strider
Star Strider el 29 de Nov. de 2018
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements 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