import file with exponential numbers

조회 수: 14 (최근 30일)
Day Hong Kim
Day Hong Kim 2021년 5월 17일
편집: Stephen23 2021년 5월 17일
Hello all, hope you having a great day. I am trying to import the file filled with exponential numbers. Is there a function to import such data or do I need to put proper data spec to read the file? I attached the file fyi. Below is just the part of the file.
0.12906E+02 0.14317E+02 0.88397E+01 0.34394E+01 -0.44398E+01 -0.10266E+02
-0.12585E+02 -0.11425E+02 -0.71798E+01 -0.13563E+00 0.65529E+01 0.10236E+02
0.12218E+02 0.11005E+02 0.83890E+01 0.29082E+01 -0.48280E+01 -0.10441E+02
-0.12556E+02 -0.11418E+02 -0.65793E+01 -0.10231E+01 0.68138E+01 0.10930E+02
0.10841E+02 0.10579E+02 0.75920E+01 0.18988E+01 -0.47565E+01 -0.10717E+02
-0.12586E+02 -0.11715E+02 -0.71195E+01 -0.10548E+01 0.53404E+01 0.97314E+01
0.13372E+02 0.11455E+02 0.88030E+01 0.29380E+01 -0.40503E+01 -0.10190E+02
-0.12504E+02 -0.11302E+02 -0.70396E+01 -0.26535E+00 0.70146E+01 0.10111E+02
0.12237E+02 0.11866E+02 0.72969E+01 0.32354E+01 -0.40348E+01 -0.10136E+02
-0.12563E+02 -0.11747E+02 -0.70156E+01 -0.18686E+00 0.54810E+01 0.10231E+02
  댓글 수: 3
Stephen23
Stephen23 2021년 5월 17일
편집: Stephen23 2021년 5월 17일
All of MATLAB's standard file importing functions correctly parse exponent notation. What have you tried so far?
Day Hong Kim
Day Hong Kim 2021년 5월 17일
편집: Day Hong Kim 2021년 5월 17일
I just noticed that the file becomes empty when I zip it. I changed the format to .txt from .d.
I have tried fread, fscanf and importdata. To read exponent notation, how should the format spec look like?

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

채택된 답변

Stephen23
Stephen23 2021년 5월 17일
You are making this far more complex than it needs to be:
M = readmatrix('1.txt')
M = 1656×6
12.9060 14.3170 8.8397 3.4394 -4.4398 -10.2660 -12.5850 -11.4250 -7.1798 -0.1356 6.5529 10.2360 12.2180 11.0050 8.3890 2.9082 -4.8280 -10.4410 -12.5560 -11.4180 -6.5793 -1.0231 6.8138 10.9300 10.8410 10.5790 7.5920 1.8988 -4.7565 -10.7170 -12.5860 -11.7150 -7.1195 -1.0548 5.3404 9.7314 13.3720 11.4550 8.8030 2.9380 -4.0503 -10.1900 -12.5040 -11.3020 -7.0396 -0.2653 7.0146 10.1110 12.2370 11.8660 7.2969 3.2354 -4.0348 -10.1360 -12.5630 -11.7470 -7.0156 -0.1869 5.4810 10.2310
  댓글 수: 2
Day Hong Kim
Day Hong Kim 2021년 5월 17일
Thank you for the answer. The extension of the original file is .d, so readmatrix doesn't work, but I think I could read the file by using textscan with proper format.
Stephen23
Stephen23 2021년 5월 17일
편집: Stephen23 2021년 5월 17일
"The extension of the original file is .d, so readmatrix doesn't work"
Specify the filetype:
M = readmatrix('1.d', 'FileType','text')

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

추가 답변 (1개)

Monika Jaskolka
Monika Jaskolka 2021년 5월 17일
편집: Monika Jaskolka 2021년 5월 17일
  댓글 수: 1
Day Hong Kim
Day Hong Kim 2021년 5월 17일
Thank you for the information!

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

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by