Effacer les filtres
Effacer les filtres

Reading few lines from a text file

7 vues (au cours des 30 derniers jours)
Shalini
Shalini le 29 Nov 2012
I have a text file and I want to read first 10 lines from that file.I tried scantext but not successful.
Can anyone suggest?
  5 commentaires
Jan
Jan le 30 Nov 2012
[MOVED from answer section] Vishal Rane wrote:
Post your comments in the comments sections only. Not many of us bother opening a thread that already has a couple of answers.
Now for your query, refer these functions and examples, Low Level File IO
Comment back in case of any doubts.
Jan
Jan le 30 Nov 2012
@Shalini: Whenever you post the term "I tried...", post the corresponding code and the occurring problems also. Otherwise we cannot give an advice for improvements.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 30 Nov 2012
Modifié(e) : Jan le 30 Nov 2012
  • fopen() to open the file (a test for success is strongly recommended)
  • Data = cell(1, 10): Pre-allocate the output
  • for loop from 1 to 10
  • fgets() to read one line, store it in Data cell.
  • end
  • fclose() to close the file

Catégories

En savoir plus sur Graphics Object Properties 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!

Translated by