Question on Reading lines from text file.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
John
le 6 Déc 2014
Réponse apportée : Azzi Abdelmalek
le 6 Déc 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!
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 6 Déc 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)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import and Export dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!