Try this:
m = randi(9, 10, 5);
dateTimes = repmat(datestr(now), 10, 1)
t1 = table(dateTimes, m(:, 1), m(:, 2), m(:, 3), m(:, 4), m(:, 5), 'VariableNames', {'Datetime', 'Var1', 'Var2', 'Var3', 'Var4', 'Var5'})
t1VariableNames = t1.Properties.VariableNames
t2VariableNames = {'Datetime', 'Pos1', 'Pos2', 'Pos3', 'Pos4', 'Pos5'}
t2 = table("Datetime", "Pos1", "Pos2", "Pos3", "Pos4", "Pos5", 'VariableNames', t2VariableNames)
for row = 1 : size(t1, 1)
[~, sortOrder] = sort(t1{row, 2:end}, 'descend');
t2(row, 2:end) = t1VariableNames(sortOrder + 1);
t2(row, 1) = t1(row, 1);
end
t2
You get:
t2 =
10×6 table
Datetime Pos1 Pos2 Pos3 Pos4 Pos5
______________________ ______ ______ ______ ______ ______
"12-Jun-2020 08:32:30" "Var4" "Var1" "Var2" "Var3" "Var5"
"12-Jun-2020 08:32:30" "Var2" "Var1" "Var3" "Var5" "Var4"
"12-Jun-2020 08:32:30" "Var5" "Var4" "Var1" "Var3" "Var2"
"12-Jun-2020 08:32:30" "Var1" "Var2" "Var4" "Var5" "Var3"
"12-Jun-2020 08:32:30" "Var2" "Var5" "Var3" "Var4" "Var1"
"12-Jun-2020 08:32:30" "Var3" "Var1" "Var2" "Var4" "Var5"
"12-Jun-2020 08:32:30" "Var2" "Var3" "Var1" "Var4" "Var5"
"12-Jun-2020 08:32:30" "Var1" "Var4" "Var2" "Var3" "Var5"
"12-Jun-2020 08:32:30" "Var2" "Var3" "Var1" "Var4" "Var5"
"12-Jun-2020 08:32:30" "Var3" "Var4" "Var1" "Var2" "Var5"
Best Answer