Perform a nested sort of a struct array based on multiple fields.
Sie verfolgen jetzt diese Einreichung
- Aktualisierungen können Sie in Ihrem Feed verfolgter Inhalte sehen.
- Je nach Ihren Kommunikationseinstellungen können Sie auch E-Mails erhalten.
Anmerkung des Herausgebers: This file was selected as MATLAB Central Pick of the Week
nestedSortStruct and nestedSortStruct2 do a nested sort of a one-dimensional struct array by two different methods. That is, the struct array is sorted by one field, then those entries of the array that have the same value for that field are sorted by a second field, etc.
If you want to sort by only one field, you can call nestedSortStruct and use a simple string instead of a cell array for fieldNamesCell, or you can simply call sortStruct.
The restrictions are that the fields must be single numbers or logicals, or chars (usually simple strings).
By default the struct array will be sorted in ascending order, but the functions include an option to sort in descending order.
nestedSortStruct will usually be faster than nestedSortStruct2. For nestedSortStruct, the speed of sorting is mostly independent of the order of the fieldnames in fieldNamesCell.
For nestedSortStruct2, the order of the fields in fieldNamesCell affects the speed. The sooner a field for which most entries in the struct array have unique values will be used to sort the struct array (i.e., the earlier its location in fieldNamesCell), the faster nestedSortStruct2 will be. If a field with mostly unique entries is the first field by which the struct array will be sorted, nestedSortStruct2 could be faster than nestedSortStruct.
nestedSortStruct could call sortStruct, and nestedSortStruct2 does call sortStruct2.
Zitieren als
Jake Hughey (2026). nestedSortStruct (https://github.com/hugheylab/nestedSortStruct), GitHub. Abgerufen .
Allgemeine Informationen
- Version 1.4.0.0 (6,06 KB)
-
Lizenz auf GitHub anzeigen
Kompatibilität der MATLAB-Version
- Kompatibel mit allen Versionen
Plattform-Kompatibilität
- Windows
- macOS
- Linux
Versionen, die den GitHub-Standardzweig verwenden, können nicht heruntergeladen werden
| Version | Veröffentlicht | Versionshinweise | Action |
|---|---|---|---|
| 1.4.0.0 | No longer ignores directions for sort order. |
||
| 1.3.0.0 | Simplified nestedSortStruct to avoid converting from cell to matrix, resulting in ~20% speedup. Thanks Jori. Fixed minor naming inconsistencies in nestedSortStruct2. |
||
| 1.2.0.0 | Fixed nestedSortStruct so column struct arrays are sorted properly. |
||
| 1.1.0.0 | Minor fix to formatting of initial comments in nestedSortStruct2.m. |
||
| 1.0.0.0 |
