Readin a txt file and exporting the data in a matrix.

조회 수: 1 (최근 30일)
Aleksej Herman
Aleksej Herman 2023년 1월 4일
편집: Karim 2023년 1월 4일
I need to exporst data from a txt. file in to mathlab. The numbers in txt. file are all ready in a matrix formation and i just need to read them in the right way. Note that the numbers are some what large. The other problem that i have is that some numbers are displaying like 5,38470670569894e-006 and i don 't know how to read the properly in matrix. The whole matrx in txt. looks like this:
0,001966941955184562 -0,003911512580972464 0,00196164813178966
0,001966941955184562 -0,003911512580972464 0,00196164813178966
0,002577327392424367 -0,003881618060113118 0,001321240553858325
0,003104487507226005 -0,003743335025340043 0,000655344148882383
0,003463648846379058 -0,003442060440921823 -6,899788122126903e-006
0,003766180779081077 -0,003084873825043694 -0,0006684846048228966
0,003904885945573184 -0,002559912110221542 -0,001333433616451176
0,003934934977298256 -0,001952111878076424 -0,001973473347759163
0,003905486096653731 -0,001314829321774319 -0,002584322588132094
0,003767358509522823 -0,0006529690917697279 -0,003111859109363536
0,003464985497078341 5,38470670569894e-006 -0,003470922583919695
0,003106816885531419 0,0006633761522620112 -0,003773810469032729
0,002579929597948367 0,001324024272730192 -0,003911300486504994
0,001970058714798917 0,001960763452954201 -0,003941156856031188
0,001330836839789801 0,002568328282739562 -0,003911653438410438
0,0006668036126518278 0,00309283850926659 -0,003773381208410974
5,9464362119452e-006 0,003449577990228116 -0,003471092606754313
-0,0006555661244248223 0,003750568084037704 -0,003112348148352735
-0,001320779285360738 0,003887961026460433 -0,002584947069810056
-0,001960979642474189 0,003917270076665622 -0,001974125585754281
-0,00257143584067414 0,003887200872328649 -0,001333484870813462
-0,003098034960566031 0,00374829266150665 -0,0006675364675250792
-0,003456406220448119 0,003445844536245728 -4,946236053912992e-006

답변 (1개)

Karim
Karim 2023년 1월 4일
편집: Karim 2023년 1월 4일
you can use the readmatrix function, remember to se the decimal seperator to a comma for you data
% 'format long' is only used to print more decimal number to the screen
% you don't need to use this in your code
format long
matrix = readmatrix( 'matrix_values.txt' ,"DecimalSeparator",",")
matrix = 23×3
0.001966941955185 -0.003911512580972 0.001961648131790 0.001966941955185 -0.003911512580972 0.001961648131790 0.002577327392424 -0.003881618060113 0.001321240553858 0.003104487507226 -0.003743335025340 0.000655344148882 0.003463648846379 -0.003442060440922 -0.000006899788122 0.003766180779081 -0.003084873825044 -0.000668484604823 0.003904885945573 -0.002559912110222 -0.001333433616451 0.003934934977298 -0.001952111878076 -0.001973473347759 0.003905486096654 -0.001314829321774 -0.002584322588132 0.003767358509523 -0.000652969091770 -0.003111859109364

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by