{
  "name": "Sort behaviour in MATLAB, GNU Octave and NumPy",
  "description": "Compares how the sort function in MATLAB, GNU Octave and NumPy handles descending order, index output, NaN placement and stability, compiled from each tool's official documentation read on 2026-11-12.",
  "page": "https://casrai.org/guides/matlab-sort",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-11-16T21:58:19Z",
  "temporalCoverage": "2026",
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Tool",
      "unit": "",
      "description": ""
    },
    {
      "name": "Function",
      "unit": "",
      "description": ""
    },
    {
      "name": "Descending order option",
      "unit": "",
      "description": ""
    },
    {
      "name": "Index output",
      "unit": "",
      "description": ""
    },
    {
      "name": "Missing/NaN placement",
      "unit": "",
      "description": ""
    },
    {
      "name": "Stability",
      "unit": "",
      "description": ""
    }
  ],
  "rows": [
    {
      "Tool": "MATLAB",
      "Function": "sort",
      "Descending order option": "sort(A,'descend')",
      "Index output": "[B,I] = sort(A)",
      "Missing/NaN placement": "Last when ascending, first when descending ('auto'); MissingPlacement first/last overrides",
      "Stability": "Stable"
    },
    {
      "Tool": "GNU Octave",
      "Function": "sort",
      "Descending order option": "mode argument \"descend\"",
      "Index output": "[s,i] = sort(x)",
      "Missing/NaN placement": "NaN treated as greater than any other value and sorted to the end; descending mode not stated",
      "Stability": "Equal elements keep their original order in the index output"
    },
    {
      "Tool": "NumPy",
      "Function": "numpy.sort",
      "Descending order option": "descending=True (new in 2.5)",
      "Index output": "numpy.argsort",
      "Missing/NaN placement": "NaN sorted to the end, also with descending=True",
      "Stability": "Default kind quicksort is not stable; stable=True selects a stable sort"
    }
  ],
  "sources": [
    {
      "title": "MathWorks: sort (MATLAB documentation)",
      "url": "https://www.mathworks.com/help/matlab/ref/double.sort.html",
      "accessed": "2026-11-12"
    },
    {
      "title": "GNU Octave manual: Rearranging Matrices (sort)",
      "url": "https://docs.octave.org/latest/Rearranging-Matrices.html",
      "accessed": "2026-11-12"
    },
    {
      "title": "NumPy documentation: numpy.sort",
      "url": "https://numpy.org/doc/stable/reference/generated/numpy.sort.html",
      "accessed": "2026-11-12"
    }
  ]
}