how can I open multiple text file only specific low and then save??

1 次查看(过去 30 天)
I would like to open 18 txt. files at once only numbers except first three characters 1-3 row.
Also, I want to save these files row 1,501~16,500 only. How can I do this? I would appreciate if somebody help me.
  2 个评论
Jan
Jan 2018-3-12
I do not understand the question: "open 18 txt. files at once only numbers except first three characters 1-3 row" What does this mean?
Houn JH
Houn JH 2018-3-12
I uploaded 18 trials of txt. files. These data contains 3 headers in 1-3 row.

请先登录,再进行评论。

采纳的回答

Akira Agata
Akira Agata 2018-3-12
Like this? Running the following code at the directory where your data (*.txt) is stored, it extracts 1501~16500 rows and saves as a new data file (*b.txt).
fileList = dir('*.txt');
for kk = 1:numel(fileList)
A = importdata(fileList(kk).name,'\t',3);
data = A.data(1501:16500,:);
[~,name,ext] = fileparts(fileList(kk).name);
fileName = [name,'b',ext];
dlmwrite(fileName,data,'precision',6);
end
  3 个评论
Akira Agata
Akira Agata 2018-3-12
Hi Houn-san,
Thank you for your response. The fileparts function returns file path, file name and file extension based on the input string. In this case, the input string fileList(kk).name contains only a file name and extension (e.g '01.txt'). So I have set the first output argument (=file path) as '~'. More details on fileparts function can be found here , but I would recommend try and see what happens by yourself, like:
>> [path,name,ext] = fileparts('01.txt')
path =
0×0 empty char array
name =
'01'
ext =
'.txt'
and
>> [path,name,ext] = fileparts('C:\folder\01.txt')
path =
'C:\folder'
name =
'01'
ext =
'.txt'
And, in this case, [name,'b',ext] returns '01b.txt'.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Low-Level File I/O 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by