필터 지우기
필터 지우기

How to import data (text and numbers) from a tabuled .dat file in MATLAB?

조회 수: 2 (최근 30일)
Hello everyone.
I need to read tabulated data from a file named 'Mechanism.dat,' which includes both numbers and words. Here are the first two lines of the .dat file as an example:
1.00 ch3och3 1.00 m 0.00 ND 1.00 ch3 1.00 ch3o 1.00 m 0.23E+20 -0.661 84139.
1.00 ch3och3 1.00 o2 0.00 ND 1.00 ch3och2 1.00 ho2 0.00 ND 0.41E+24 2.000 44910.
I tried using the command
table0 = readtable('Mechanism.dat', 'Delimiter', ' ', 'MultipleDelimsAsOne', true);
disp(table0)
however it replaces the words with the numerical value NaN. How can I overcome this issue?"

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2024년 1월 4일
It is reading ok:
% *.data can be uploaded and thus, .txt file format is taken. Both works
% table0 = readtable('Mechanism.dat', 'Delimiter', ' ', 'MultipleDelimsAsOne', true);
table0 = readtable('Mechanism.txt', 'Delimiter', ' ', 'MultipleDelimsAsOne', true);
disp(table0)
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 Var12 Var13 Var14 Var15 ____ ___________ ____ ______ ____ ______ ____ ___________ ____ ________ _____ ______ _______ ______ _____ 1 {'ch3och3'} 1 {'m' } 0 {'ND'} 1 {'ch3' } 1 {'ch3o'} 1 {'m' } 2.3e+19 -0.661 84139 1 {'ch3och3'} 1 {'o2'} 0 {'ND'} 1 {'ch3och2'} 1 {'ho2' } 0 {'ND'} 4.1e+23 2 44910
% Alt. way is readcell
table1 = readcell('Mechanism.txt', 'Delimiter', ' ', 'MultipleDelimsAsOne', true);
disp(table1)
{[1]} {'ch3och3'} {[1]} {'m' } {[0]} {'ND'} {[1]} {'ch3' } {[1]} {'ch3o'} {[1]} {'m' } {[2.3000e+19]} {[-0.6610]} {[84139]} {[1]} {'ch3och3'} {[1]} {'o2'} {[0]} {'ND'} {[1]} {'ch3och2'} {[1]} {'ho2' } {[0]} {'ND'} {[4.1000e+23]} {[ 2]} {[44910]}
  댓글 수: 2
Jonatan Eisermann
Jonatan Eisermann 2024년 1월 5일
Thank you. That's correct. There was an error in my .dat file, so it wasn't working.
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2024년 1월 5일
Most welcome. Glad to be of some help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by