how to sort push button
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Jan
am 18 Jul. 2013
Bearbeitet: Jan
am 18 Jul. 2013
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 Kommentare
Jan
am 20 Jul. 2013
@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.
Weitere Antworten (2)
Jan
am 17 Jul. 2013
- 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 Kommentare
Jan
am 17 Jul. 2013
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.
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!