Effacer les filtres
Effacer les filtres

How can I convert an array to a matrix?

244 vues (au cours des 30 derniers jours)
Vishnu M S
Vishnu M S le 29 Jan 2013
I have an array like B=[2 3 1 5 2 8 1 7 9 1 5 2 4 6 3 9 3 1 7 0 7 2 8 6].
I need this elements in a matrix called A like
A=
2 3 1 5 2 8 1 7
9 1 5 2 4 6 3 9
3 1 7 0 7 2 8 6
Please help...

Réponse acceptée

José-Luis
José-Luis le 29 Jan 2013
B=[2 3 1 5 2 8 1 7 9 10 5 21 4 6 3 9 3 1 7 0 7 2 8 6];
A = reshape(B,8,3)'

Plus de réponses (2)

Andreas Goser
Andreas Goser le 29 Jan 2013
In MATLAB all arrays are matrices... You may achieve what you need by using the RESHAPE command.

Martin
Martin le 29 Jan 2013
As Jose mentioned the reshape function is a really good one. The help file on that one is really useful for explaining how it works.

Catégories

En savoir plus sur Matrices and Arrays 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