M.Patil
M.Patil

Reputation: 81

Sort table according to another vector

a=[44;60;11]; b=[9;8;4]; c=[4;16;23];
T=table(a,b,c);
d=[2;3;1];

Sort rows of table T according to index vector "d"

Upvotes: 0

Views: 55

Answers (2)

bidi
bidi

Reputation: 66

So you're sorting the rows according to the indices in your vector d.

tSort = T(d,:);

Upvotes: 2

Tommaso Belluzzo
Tommaso Belluzzo

Reputation: 23685

If I understood your question correctly, this should work as intended:

a=[44;60;11]; b=[9;8;4]; c=[4;16;23];
T=table(a,b,c);
d=[2;3;1];

T_new = T(:,d);

The last line will swap the table columns (to be exact, the table variables) according to the indices in vector d.

Upvotes: 1

Related Questions