import file with exponential numbers

14 vues (au cours des 30 derniers jours)
Day Hong Kim
Day Hong Kim le 17 Mai 2021
Modifié(e) : Stephen23 le 17 Mai 2021
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 commentaires
Stephen23
Stephen23 le 17 Mai 2021
Modifié(e) : Stephen23 le 17 Mai 2021
All of MATLAB's standard file importing functions correctly parse exponent notation. What have you tried so far?
Day Hong Kim
Day Hong Kim le 17 Mai 2021
Modifié(e) : Day Hong Kim le 17 Mai 2021
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?

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 17 Mai 2021
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 commentaires
Day Hong Kim
Day Hong Kim le 17 Mai 2021
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 le 17 Mai 2021
Modifié(e) : Stephen23 le 17 Mai 2021
"The extension of the original file is .d, so readmatrix doesn't work"
Specify the filetype:
M = readmatrix('1.d', 'FileType','text')

Connectez-vous pour commenter.

Plus de réponses (1)

Monika Jaskolka
Monika Jaskolka le 17 Mai 2021
Modifié(e) : Monika Jaskolka le 17 Mai 2021
  1 commentaire
Day Hong Kim
Day Hong Kim le 17 Mai 2021
Thank you for the information!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by