Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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 comentarios
Jan
Jan el 12 de Mzo. de 2018
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 el 12 de Mzo. de 2018
I uploaded 18 trials of txt. files. These data contains 3 headers in 1-3 row.

Iniciar sesión para comentar.

Respuesta aceptada

Akira Agata
Akira Agata el 12 de Mzo. de 2018
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 comentarios
Akira Agata
Akira Agata el 12 de Mzo. de 2018
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 el 12 de Mzo. de 2018
Thanks. It really helpful for me.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Low-Level File I/O en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by