Sorting of column 'folder' present in 'struct'
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alberto Acri
am 8 Nov. 2022
Bearbeitet: Stephen23
am 10 Nov. 2022
I have such a 'struct' and I want to make the column 'folder' in order. How can I do this?
Akzeptierte Antwort
Adam Danz
am 9 Nov. 2022
Sounds like you want natural order sorting. There are some File Exchange submissions that do this (example). But if the format you shared is consistent across all paths, it would also be easy to use regular expressions to extract the ending numeric values and then sort those values.
This would have been easier to demonstrate if the paths were provided as text rather than a screenshot.
str = 'C:\Users\me\folderOne\folder2\docs\Data 11';
nstr = regexp(str,'\d+$','match','once');
n = str2double(nstr)
[~, sortidx] = sort(n)
Then use sortidx to sort whatever you're sorting.
2 Kommentare
Adam Danz
am 9 Nov. 2022
The variable str in my answer is just an example of 1 path. In your case, you'll define str as
str = {B.folder};
then you'll use sortidx from my answer B
B_sorted = B(sortidx);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Database Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!