Effacer les filtres
Effacer les filtres

load multiple files in right order

4 vues (au cours des 30 derniers jours)
Nik Rocky
Nik Rocky le 1 Déc 2020
Modifié(e) : Stephen23 le 18 Avr 2021
Hello,
I'm loading multiple mat-files in workspace, the names of files are:
Schweben_Meg_2_2-01_SNR_-030_PLL.mat
Schweben_Meg_2_2-01_SNR_-015_PLL.mat
Schweben_Meg_2_2-01_SNR_000_PLL.mat
Schweben_Meg_2_2-01_SNR_015_PLL.mat
Schweben_Meg_2_2-01_SNR_030_PLL.mat
the answers will be writen to one result files. The problem - MATLAB loads this files in "wrong" order.
First it takes:
Schweben_Meg_2_2-01_SNR_-015_PLL.mat
than
Schweben_Meg_2_2-01_SNR_-030_PLL.mat
than
Schweben_Meg_2_2-01_SNR_000_PLL.mat
.....
I want to get a loading order:
Schweben_Meg_2_2-01_SNR_-030_PLL.mat first
than
Schweben_Meg_2_2-01_SNR_-015_PLL.mat
than
Schweben_Meg_2_2-01_SNR_000_PLL.mat
it is possible to read a data in "right" order without rename of all the files? (I have about 1000x of thoose files)
Thank you!
  2 commentaires
Timo Dietz
Timo Dietz le 1 Déc 2020
I guess you have to isolate the PLL(?) values and sort them separately.
Then re-build the filenames to be loaded.
Nik Rocky
Nik Rocky le 1 Déc 2020
Thanks, I try to implement a natsortfiles-function now.
Actually, I made already a workaround tool to resort my results. Small script that turn a first and second row of result. But it's not really nice =)

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 1 Déc 2020
Modifié(e) : Stephen23 le 18 Avr 2021
You could download my FEX submission natsortfiles:
and use the regular expression '-?\d{3}' (or similar), e.g.:
D = 'path to the folder where the files are saved';
S = dir(fullfile(D,'Schweben*PLL.mat'));
S = natsortfiles(S,'-?\d{3}'); % alphanumeric sort by filename
... etc
  9 commentaires
Stephen23
Stephen23 le 2 Déc 2020
Modifié(e) : Stephen23 le 2 Déc 2020
sys_var = dir('**/*.mat');
[~,ndx] = natsortfiles({sys_var.name},'-?\d{3}');
sys_var = sys_var(ndx);
"Thank you Stephen, it works great! "
Please remember to accept my answer if it helped you.
Nik Rocky
Nik Rocky le 2 Déc 2020
Great, short and nice!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by