Effacer les filtres
Effacer les filtres

how to re order a matrix based on a vector ?

10 vues (au cours des 30 derniers jours)
Niki
Niki le 16 Sep 2015
Réponse apportée : dpb le 16 Sep 2015
I have a matrix like below
A =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
each column is a variable for example we have 4 in this example I want to reorder it based on another vector that i have for example I want to reorder it based on the following vector
t = [ 2 1 3 4]
so the output will look like
A =
2 16 3 13
11 5 10 8
7 9 6 12
14 4 15 1
It is important that I sort the matrix using a given vector index

Réponses (1)

dpb
dpb le 16 Sep 2015
Clearly you haven't tried the obvious...
>> A(:,t)
ans =
2 16 3 13
11 5 10 8
7 9 6 12
14 4 15 1
>>

Catégories

En savoir plus sur Shifting and Sorting 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