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

Answers (1)

Joseph Benin
Joseph Benin on 16 Apr 2018
Edited: Walter Roberson on 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 Comments

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

Sign in to comment.

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Asked:

on 16 Apr 2018

Commented:

on 11 Aug 2020

Community Treasure Hunt

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

Start Hunting!