フィルターのクリア

How to automatically open the files in this m-code

5 ビュー (過去 30 日間)
yc j
yc j 2016 年 1 月 26 日
編集済み: Stephen23 2021 年 4 月 26 日
hello. I couldn't solve the problem from last answers.. so I bring the m-code I wrote as below:
clear
clc
fileID = fopen('number_of_filename.txt','w');
fprintf(fileID,'%6s\n','number');
for ii=1:100
[file,path]=uigetfile('*.txt');
file_name=file
filename=fullfile(path,file);
fid = load(filename);
idx = find(file_name == ' ', 1, 'first');
part1 = file_name(1:idx-1);
fprintf(fileID,'%6s\n',part1);
end
fclose(fileID);
The name of the txt files are 0.5 f.txt, 1.0 f.txt, 1.1 f.txt, 3.0 f.txt, 5.6 f.txt, 10.0 f.txt ... and so on. The numbers are random.
Above code will give me the 'number part of the file name' only, which are 0.5, 1.0, 1.1, 3.0, 5.6, 10.0 ... and so on.
Here, I am to select txt files one by one, over and over. The problem is, I have over 1 thousand txt files....
How can I modify the above code to let the m-file run all 1 thousand txt files by itself?
  3 件のコメント
yc j
yc j 2016 年 1 月 26 日
i can't... the file name means something and i need them...
Stephen23
Stephen23 2016 年 1 月 26 日
編集済み: Stephen23 2016 年 1 月 26 日

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

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 1 月 26 日
  2 件のコメント
Stephen23
Stephen23 2016 年 1 月 26 日
編集済み: Stephen23 2021 年 4 月 26 日
And then use my FEX submission natsortfiles to get the files into numeric order:
S = dir(...);
S = natsortfiles(S,'\d+\.?\d*');
for k = 1:numel(S)
S(k).name
...
end
Walter Roberson
Walter Roberson 2016 年 1 月 26 日
It turns out in another Question that the names have a variable number of decimal places that sometimes include trailing 0 and sometimes do not.

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

カテゴリ

Help Center および File ExchangeAdding custom doc についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by