3
$\begingroup$

I have such a problem. I try to evaluate and plot the spectrum of large list, and this is what I get:

 list = ReadList["textfile.txt"]
 ListPlot[Abs[Fourier[list]]]

 Fourier::fftl: Argument 
 {1,0.99995,0.9998,0.99955,0.9992,0.99875,0.998201,0.997551,0.996802,0.995953,0.995004,0.993956,0.992809,0.991562,0.990216,
 <<21>>,0.935897,0.932327,0.928665,0.924909,0.921061,0.917121,0.913089,0.908966,0.904752,0.900447,0.896052,0.891568,0.886995,0.882333,<<9950>>} 
 is not a non-empty list or rectangular array of numeric quantities. >>

So, I think this could happen because of symbols such as

 <<21>>

in the list. But I don't know how to fix this to make Fourier command work correctly.

UPD: sample of the file

 {1, 0.99995, 0.9998, 0.99955, 0.9992, 0.99875, 0.998201, 0.997551, \
 0.996802, 0.995953, 0.995004, 0.993956, 0.992809, 0.991562, 0.990216, \
 0.988771, 0.987227, 0.985585, 0.983844, 0.982004, 0.980067, 0.978031, \
 0.975897, 0.973666, 0.971338, 0.968912, 0.96639, 0.963771, 0.961055, \
 0.958244, 0.955336, 0.952334, 0.949235, 0.946042, 0.942755, 0.939373, \
 0.935897, 0.932327, 0.928665, 0.924909, 0.921061, 0.917121, 0.913089, \
 0.908966, 0.904752, 0.900447, 0.896052, 0.891568, 0.886995, 0.882333, \
 0.877583, 0.872745, 0.867819, 0.862807, 0.857709, 0.852525, 0.847255, \
 0.841901, 0.836463, 0.830941, 0.825336, 0.819648, 0.813878, 0.808028, \
 0.802096, 0.796084, 0.789992, 0.783822, 0.777573, 0.771246, 0.764842, \
 0.758362, 0.751806, 0.745174, 0.738469, 0.731689, 0.724836, 0.717911, \
 0.710914, 0.703845, 0.696707, 0.689498, 0.682221, 0.674876, 0.667463, \
 0.659983, 0.652437, 0.644827, 0.637151, 0.629412, 0.62161, 0.613746, \
 0.60582, 0.597834, 0.589788, 0.581683, 0.57352, 0.5653, 0.557023, \
 0.54869, 0.540302, 0.531861, 0.523366, 0.514819, 0.50622, 0.497571, \
 0.488872, 0.480124, 0.471328, 0.462485, 0.453596, 0.444662, 0.435682, \
 0.42666, 0.417595, 0.408487, 0.39934, 0.390152, 0.380925, 0.37166, \
 0.362358, 0.353019, 0.343646, 0.334238, 0.324796, 0.315322, 0.305817, \
 0.296281, 0.286715, 0.277121, 0.267499, 0.25785, 0.248175, 0.238476, \
 0.228753, 0.219007, 0.209239, 0.19945, 0.189641, 0.179813, 0.169967, \
 }

And

 DeleteCases[list, _Real]
 {1, 1, 1, -5 - 9.18301 e, -1, -1, -1, -1}

Also

 NumericQ[list]
 False

UPD2: LINK TO THE FILE http://www.filedropper.com/fourier (It's interesting that the file itself doesn't contain any numbers in scientific (with e) notation).

$\endgroup$
6
  • $\begingroup$ Can we get a sample of this file you are importing ? $\endgroup$
    – Sektor
    Sep 17, 2015 at 19:20
  • 1
    $\begingroup$ Can you be more specific about the contents of list? Is it true that And @@ (NumericQ /@ list), for instance? $\endgroup$ Sep 17, 2015 at 19:20
  • $\begingroup$ It looks like your list contains non-numeric elements. Try evaluating N@list~DeleteCases~_Real to see a list of the problem elements. $\endgroup$ Sep 17, 2015 at 19:29
  • $\begingroup$ Updated with the sample $\endgroup$
    – newt
    Sep 17, 2015 at 19:32
  • $\begingroup$ DeleteCases[list] => {1, 1, 1, -5 - 9.18301 e, -1, -1, -1, -1}; NumericQ[list] => False $\endgroup$
    – newt
    Sep 17, 2015 at 19:34

1 Answer 1

7
$\begingroup$

I've noticed before that when importing text files into Mathematica, depending on how the text file encodes numbers, you might get odd results, such as expressions like -5 - 9.18301 e due to the file encoding the number as "-9.18301e-5", which is generally fine, but doesn't read correctly with ReadList[]. Instead, try Import[filename, "Table"].

Edit:

I downloaded the file linked in your post. Indeed, the error seems to be due entirely to a single entry that is in scientific notation: "-9.18301e-05". Import[filename, "Table"] works fine, as does Abs@Fourier[Flatten@Import[filename, "Table"]] (note that the Flatten is due to "Table" importing data as a matrix).

As noted by Simon Woods, Abs@Fourier[ReadList[filename, Number]] also works fine.

$\endgroup$
11
  • $\begingroup$ You can also use ReadList[filename, Number] $\endgroup$ Sep 17, 2015 at 19:44
  • $\begingroup$ So, If I try Import[filename, "Table"] I got Import::noelem: "The Import element \"Table\" is not present when importing as \!(\"Text\")." If I try Import[filename] so the result isn't table of numbers (it's symbols) and again in cannot be used in Fourier operation $\endgroup$
    – newt
    Sep 17, 2015 at 19:45
  • $\begingroup$ ReadList[filename, Number] solves the problem. But what if the most part of my file contains such non-numerical symbols like "-9.18301e-5", so I cannot just erase them? How can I transform all of them to make Fourier operation be possible? $\endgroup$
    – newt
    Sep 17, 2015 at 19:48
  • $\begingroup$ That error does not make sense to me (about the Table import). I can't reproduce it. Can you post your file somewhere that we can look at it? "-9.18301e-5" is a number, it's just encoded in scientific notation. $\endgroup$
    – nben
    Sep 17, 2015 at 19:51
  • $\begingroup$ @user21382 I added link to my file. It's interesting that file itself does not contain any numbers in scientific notation. $\endgroup$
    – newt
    Sep 17, 2015 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.