I have a code that generates various tables like
T1 = {{-1., 0.880673, 0.880673}, {-0.9, 0.870404, 0.870404}, {-0.8,
0.839598, 0.839598}, {-0.7, 0.788252, 0.788252}, {-0.6, 0.716371,
0.716371}, {-0.5, 0.62399, 0.62399}, {-0.4, -0.066081,
1.08857}, {-0.3, -0.515704, 1.27288}, {-0.2, -0.922929,
1.37822}, {-0.1, -1.30305, 1.43556}, {0.,
1.45392, -1.53348}, {0.1, -1.30305, 1.43556}, {0.2, -0.922929,
1.37822}, {0.3, -0.515704, 1.27288}, {0.4, -0.066081,
1.08857}, {0.5, 0.62399, 0.62399}, {0.6, 0.716371,
0.716371}, {0.7, 0.788252, 0.788252}, {0.8, 0.839598,
0.839598}, {0.9, 0.870404, 0.870404}, {1., 0.880673, 0.880673}};
For each {a,b,c}
, I want to swap the second item~(b) with the third one~(c) if b>c
. In the above table, this procedure should apply only to {0.,1.45392,-1.53348}
which can be done using
{T1[[11, 2]], T1[[11, 3]]} = {T1[[11, 3]], T1[[11, 2]]}
As I am dealing with larger tables like above with different numbers of elements and orders, I am looking for a solution that automatically checks the criteria and swap the elements if it was needed.