Borrar filtros
Borrar filtros

Question on Reading lines from text file.

1 visualización (últimos 30 días)
John
John el 6 de Dic. de 2014
Respondida: Azzi Abdelmalek el 6 de Dic. de 2014
Hi,
I have the following data in the txt file:
2 34 5 6 7 8
34 56 77 12 3
11 34 55 66 89 1
12 34 55 67 8 1
45 67 8 1 2 14
23 45 1 2 8 9
I want to read my file from third line to 5th line and save it in a matrix say A. That is A should be:
A = 11 34 55 66 89 1
12 34 55 67 8 1
45 67 8 1 2 14
I can do this if I have to read my lines from the start to a specified number of lines using fopen and fgetl ...however, I cant figure out how to do this for the above situation. Please Help!

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 6 de Dic. de 2014
fid=fopen('file.txt')
for k=1:2
fgetl(fid);
end
A=zeros(3,6)
for k=1:3
A(k,:)=str2num(fgetl(fid))
end
fclose(fid)

Más respuestas (0)

Categorías

Más información sobre Data Import and Export 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