Effacer les filtres
Effacer les filtres

How transform a vector into a Matrix

391 vues (au cours des 30 derniers jours)
So
So le 19 Mai 2016
Modifié(e) : So le 19 Mai 2016
Hello, I am trying to transform a line vector of length x² to a matrix size x*x. For example,
Vector = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
and I want
Matrix = [ 1 5 9 13; 2 6 10 14; 3 7 11 15; 4 8 12 16]
This is only an example, I am trying to write a function for any vector. Thank you.

Réponse acceptée

Stephen23
Stephen23 le 19 Mai 2016
Modifié(e) : Stephen23 le 19 Mai 2016
Use reshape:
>> V = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16];
>> M = reshape(V,4,4)
M =
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
  1 commentaire
So
So le 19 Mai 2016
Modifié(e) : So le 19 Mai 2016
Oh yeah i made a mistak.. thank you :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Cartesian Coordinate System Conversion 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!

Translated by