How to read in a .dat file into matlab?

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

Risposte (1)

Joseph Benin
Joseph Benin il 16 Apr 2018
Modificato: Walter Roberson il 16 Apr 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 Commenti

didn't work
Akra Roy: please attach a copy of your file and your code attempt

Accedi per commentare.

Categorie

Scopri di più su Data Import and Analysis in Centro assistenza e File Exchange

Richiesto:

il 16 Apr 2018

Commentato:

il 11 Ago 2020

Community Treasure Hunt

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

Start Hunting!

Translated by