Sorting of column 'folder' present in 'struct'

I have such a 'struct' and I want to make the column 'folder' in order. How can I do this?

3 件のコメント

Jonas
Jonas 2022 年 11 月 9 日
i don't understand, the column folder is already sorted correctly?
Alberto Acri
Alberto Acri 2022 年 11 月 9 日
Lines 4-5-6 (where '\GLOBAL\DATA 11' is listed) I would like to have them at the bottom of the list (after '\GLOBAL\DATA 6')
Stephen23
Stephen23 2022 年 11 月 10 日
編集済み: Stephen23 2022 年 11 月 10 日
Another approach is to download NATSORTFILES here:
unzip it and then use it like this:
A = 'C:\Users\Alberto\Desktop\GLOBAL';
B = dir(fullfile(A,'DATA*','*'));
B = natsortfiles(B,[],'rmdot','noext');

サインインしてコメントする。

 採用された回答

Adam Danz
Adam Danz 2022 年 11 月 9 日

0 投票

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)
n = 11
[~, sortidx] = sort(n)
sortidx = 1
Then use sortidx to sort whatever you're sorting.

2 件のコメント

Alberto Acri
Alberto Acri 2022 年 11 月 9 日
I thank you for your answer @Adam Danz. I don't quite understand how to apply them to my code.
I am using these lines of code:
A = 'C:\Users\Alberto\Desktop\GLOBAL';
B = dir(fullfile(A,'DATA*','*'));
B(ismember({B.name},{'.','..'})) = [];
Within the GLOBAL folder are several "DATA #" folders where # is a number from 1 to 50.
Within each "DATA" folder there are 3 folders "a", "c" and "s".
The "DATA #" folders I would like them in order.
Adam Danz
Adam Danz 2022 年 11 月 9 日
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);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 11 月 8 日

編集済み:

2022 年 11 月 10 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by