best way in terms of performance to read a text file

2 vues (au cours des 30 derniers jours)
Salvatore Mazzarino
Salvatore Mazzarino le 28 Sep 2012
I have to read values from text file that have this body:
1 2 3 4 5 6 7 8 9 10
after having read every of those value I would copy them in a vector. which is the best way in terms of speed and performance?

Réponse acceptée

Sven
Sven le 28 Sep 2012
Modifié(e) : Sven le 28 Sep 2012
If your text file has exactly what you've got there (numbers separated by spaces):
---== contents of test.txt ==---
1 2 3 4 5 6 7 8 9 10
--------------------------------
Then just use importdata
A = importdata(filename)
A =
1 2 3 4 5 6 7 8 9 10
Quick, simple. MATLAB will be pretty optimised to read this kind of file. Is that what you were looking for?

Plus de réponses (1)

Walter Roberson
Walter Roberson le 29 Sep 2012
fopen(), fscanf(), fclose()

Catégories

En savoir plus sur Low-Level File I/O dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by