필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Houn JH
Houn JH 2018년 3월 10일
댓글: Houn JH 2018년 3월 12일
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'.
Houn JH
Houn JH 2018년 3월 12일
Thanks. It really helpful for me.

댓글을 달려면 로그인하십시오.

추가 답변 (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