How to create a vector of this output?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kash Costello
le 29 Nov 2018
Commenté : Star Strider
le 29 Nov 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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/197575/image.png)
... and so on and so forth.
Thanks a lot!
0 commentaires
Réponse acceptée
Star Strider
le 29 Nov 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!