how to sort push button
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Jan
il 18 Lug 2013
Modificato: Jan
il 18 Lug 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 Commenti
Jan
il 20 Lug 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.
Più risposte (2)
Jan
il 17 Lug 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 Commenti
Jan
il 17 Lug 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.
Vedere anche
Categorie
Scopri di più su File Operations in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!