Order of filenames is wrong

5 ビュー (過去 30 日間)
Nik Rocky
Nik Rocky 2020 年 7 月 3 日
編集済み: Stephen23 2020 年 7 月 4 日
Hello,
I have save some measures in loop with
SNR = 30
SNR_steps = 15
-SNR:SNR_steps:SNR
ans = -30 -15 0 15 30
I use SNR also in part of the filename and I get:
The Problem: the order of files in the folder is (-015 before -030), but I want to have -030, -015, 000, 015, 030...
Why is this happening, and how can I avoid this situation?
Thank you!
  3 件のコメント
Nik Rocky
Nik Rocky 2020 年 7 月 3 日
編集済み: Nik Rocky 2020 年 7 月 3 日
Hello Rik, thank you for response!
I'm using ubuntu 16.04. And I need this fileorder by reading and plotting wich another MATLAB script.
For every value I get a row, in this case:
Measure_020 =
0.2112 0.3973 %< should be second row
0.0825 0.6542 %< should be first row
0.5479 0.1426
0.5818 0.1912
0.5904 0.1303
I sort the data already with small script:
l = dir('**/*.mat');
for k = 1:length(l)
[filepath,name,ext] = fileparts(l(k).name);
Correct_Folder = l(k).folder;
Correct_Name = l(k).name;
Correct_Folder_Name = fullfile(Correct_Folder,Correct_Name);
load(Correct_Folder_Name)
disp(Correct_Name)
temp = M(1,:);
M(1,:)=M(2,:);
M(2,:)=temp;
save(Correct_Folder_Name)
end
but how can I avoid it i future?
Rik
Rik 2020 年 7 月 3 日
Use the function suggested in the answer below to read the filenames in the order that fills your array in the order that makes sense to you.

サインインしてコメントする。

回答 (1 件)

KSSV
KSSV 2020 年 7 月 3 日
  2 件のコメント
Image Analyst
Image Analyst 2020 年 7 月 3 日
Not sure it will work, but there are lots of options with it to try
Stephen23
Stephen23 2020 年 7 月 3 日
編集済み: Stephen23 2020 年 7 月 4 日
Note that a suitable regular expression will have to be provided as the second input argument, as by default natsortfiles uses the natsort default of matching digits only (i.e. positive integers including zero). For example:
'[-+]?\d+'
or in case you only need to match that one number:
'[-+]?\d+(?=_PLL)'
You should also return its third output argument to confirm that the required numbers are being correctly converted to numeric.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpectral Estimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by