How to successfully deploy Matlab function [B, IX] = sort (A, ...)

IX is a permutation vector of the corresponding column of A

M := Matrix(6, 3, [2, 3, 3, 5, 7, 8, 12, 5, 9, -3, 4.1, 7, 7, 7, -3, 9, 3, 8]):

M;

L := <(seq(op(convert(sort(M[() .. (), j]), list)), j = 1 .. op(M)[2]))>;

L := ArrayTools[Alias](L, [op(M)[1 .. 2]], Fortran_order);

P := Matrix(op(M)[1 .. 2], (i, j)-> ListTools[Search](L[i, j], M[() .. (), j]));

# from Matlab