how to sort push button
1 回表示 (過去 30 日間)
古いコメントを表示
i have 10 number of folders. when i run the main.m file the folders shows like 10 number of push buttons. the push button having the names of that folder. now i need to sort the push buttons by folder created date, please help me. thanks in advance
0 件のコメント
採用された回答
Jan
2013 年 7 月 18 日
編集済み: Jan
2013 年 7 月 18 日
I assume, you want:
top_dir = dir(dir_name);
[dummy, index] = sort([top_dir.datenum]);
top_dir = top_dir(index);
Now the files and folders inside the struct top_dir are chronologically sorted.
Working with relative path names is dangerous. Matlab tries to be smart and searches in all folders of the Matlab path. Better use absolute paths and avoid to append a data folder to the Matlab path:
currentPath = cd;
dir_name = fullfile(currentPath, 'Code');
top_dir = dir(dir_name);
fullfile is smarter than hardcoding the file separator: 1. it considers existing separators, e.g. in "C:\", and it cares about the preferences of the operating system: \ or /
2 件のコメント
Jan
2013 年 7 月 20 日
@godwin: The code I have posted sorts the names of the folder according to the dates. Afterwards you create the buttons. And because the names are sorted already, the buttons have the same order also. So there is no reason to sort the buttons. It is not even meaningful to sort the buttons, when the contents of the buttons are sorted already.
Btw. char(Name1(1:end)) can be simplified to Name1.
その他の回答 (2 件)
Jan
2013 年 7 月 17 日
- Obtain the creation date of the folders by dir. The replied field datenum is the best value to sort for.
- Let sort find the wanted order.
- Set the strings according to this order.
If you need a more explicit implementation, show us, what you have done so far and ask more explicitly for a specific problem.
3 件のコメント
Jan
2013 年 7 月 17 日
Where did you get these names from? I guess you use the DIR command, and then you can use the .datenum field directly for sorting also. Please provide the relevant part of the code, because we cannot guess how you create this list of names.
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!