Sorting a structure array
Afficher commentaires plus anciens
I have used a previous code that creates a structure array with the name of several subfolder where i want to import data
% Path of the main folder :
yourpath = 'D:\Dropbox\...';
% Get all the subfolders
ContentInFold = dir(yourpath);
SubFold = ContentInFold([ContentInFold.isdir]); % keep only the directories
% Loop on each folder
FColLocal = [];
for i = 3:length(SubFold) % start at 3 to skip . and ..
filetoread = fullfile(yourpath,SubFold(i).name,'FCol_LocalForce.out'); % <- this is the "Fcol_LocalForce.txt" file of the ith subfolders
% then type your code to read the text files and store in one variable
FColLocal{end+1} = dlmread(filetoread, ' ', [10 0 1008 0]); % the format depends of your files
end
In the SubFold structure array, thats where i would like to sort the field 'name' with a diferend order of the determined by Matlab.
The problem is that the field 'name' is formed with characteres of the type:
'1._0.005._0.2_.4._2'
'10._0.005._0.2_.16._4' ,
'100._0.002._0.5_.4._16'
The field name corresponds to subfolder name (except the first 2 rows),

but I would like to change to (as it is ordered in the windows folder)
'1._0.005._0.2_.4._2' ,
'2._0.005._0.2_.4._4'
'3._0.005._0.2_.4._8'
...
where only the first character of the name field controles the sorting (ascending).
Thanks
2 commentaires
Jon
le 26 Juil 2019
Could you please further clarify. Please make a short example list of the filenames in the order that they are returned by directory and then for those same filenames please list how you would like them sorted. I think you have tried to do that above, but I am confused by your listing for example of '3._0.005._0.2_.4._8', I don't see that filename anywhere in the screenshot you have, and don't really know what you are trying to show.
FabioP
le 26 Juil 2019
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
