How to read in a .dat file into matlab?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Joseph Benin
2018-4-16
编辑:Walter Roberson
2018-4-16
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!