reference elements in a matrix based on values in a vector

1 vue (au cours des 30 derniers jours)
Christopher
Christopher le 23 Fév 2014
Modifié(e) : Christopher le 23 Fév 2014
I have the 1x9 vector [5 3 2 6 7 26 4 33 3]
I want to obtain the matrix [5 3 2; 6 7 26; 4 33 3] using completely vectorized code. How can this be done?
As a start, I have vectorized code to build the 3x3 matrix [ 1 2 3; 4 5 6; 7 8 9], so that the values are the vector columns, but I don't know how to do the vectorized referencing.
Thanks

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 23 Fév 2014
Modifié(e) : Azzi Abdelmalek le 23 Fév 2014
A= [5 3 2 6 7 26 4 33 3]
out= reshape(A,3,[])'
  4 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 23 Fév 2014
How?
Christopher
Christopher le 23 Fév 2014
Modifié(e) : Christopher le 23 Fév 2014
There are two 7's because there are two 5's. The 5th element in the vector is =7. The numbers in the matrix should refer to the column number in the vector. You see?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by