How to read in a .dat file into matlab?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to read in a data file into MATLAB, but it is not working correctly. My code:
Convergence = fopen('convergence.dat','r');
I am getting
Convergence = 3
but it should output something like:
Iteration Continuity Energy
1 0.302698 0.402993
2 0.470715 0.617098
3 0.507262 0.665507
4 0.469905 0.609844
5 0.407501 0.522219
6 0.362136 0.460129
7 0.321902 0.40361
8 0.337875 0.413282
9 0.357806 0.438051
10 0.380913 0.475059
11 0.389145 0.483145
12 0.272243 0.373424
0 commentaires
Réponses (1)
Joseph Benin
le 16 Avr 2018
Modifié(e) : Walter Roberson
le 16 Avr 2018
fopen opens the file and provides a handle to the file (aka FileID). Once you've opened the file you will need to read from it using something like fgetl or fscanf? Alternatively you could also use readtable https://www.mathworks.com/help/matlab/import_export/ways-to-import-text-files.html. If the data file was saved from within Matlab you could also just load it.
2 commentaires
Voir également
Catégories
En savoir plus sur Low-Level File I/O 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!