|Apr17-11, 02:45 PM||#1|
Importing data into mathematica
I'm having trouble getting data into mathematica.
I have a text file will a list with members seperated by returns (enters) that I want to import as an array. I tried:
All of which failed to find the file, even though it is stored in the same directory. Finally I tried
(the ... is all the folders in between)
And it gives me this message (not an error, its just this is all it outputs):
System`Convert`TableDump`GetData(System`Convert`TableDump`ImportTable(C :\Users\Darin\Documents\Darin Live Sync Folder\Organizations\MIT\Classes\5_74 QMII\PSet 5\data.txt))
I'm pulling my hair out trying to get this thing to work, any guidance would be deeply appreciated.
The .nb file is stored in the same directory as the data file.
|Apr17-11, 04:41 PM||#2|
I tried with a .csv file as well, same message, no table.
|Apr17-11, 06:37 PM||#3|
|Apr17-11, 06:40 PM||#4|
Importing data into mathematica
I would use the SetDirectory command first. Also, be aware that you have to change the slashes to \\ so that it will parse correctly.
|Apr18-11, 02:06 PM||#5|
Thanks, I tried both those things, same message:
Incidentally, it treats both \\ and / the same and parses both 'correctly' in that it understands the input and seems to be going to right place. If I use \ then I get an error message, and if I don't put in a file name that is there I get a not found message.
So it is finding the file, and is not giving an error, but its not turning it into an array like I want. The file is just the numbers separated by commas (or in the text file case by returns).
|Apr18-11, 02:54 PM||#6|
This may be somewhat Mathematica-version dependent, but let's see what we can do for you.
I created a tiny text file containing 3 characters
where \n represents tapping the Enter key.
To simplify this whole directory business I put that in my C:\Program Files\Wolfram Research\Mathematica\x.y directory, where x.y is my current version number. You can test using that method or if you have your directory handling figured out you can ignore this.
I then hopped into Mathematica and did this (literally copying and pasting exactly my notebook cell contents). Note: My textual description not preceded by In or Out was not part of my notebook contents, it is just to explain what is going on.
But Mathematica will often "lie to you", presenting things that look like one thing but are another. FullForm will more often show you what something really is.
So that read the file as a single string and that isn't convenient.
So then I did exactly this
That looks exactly like what I think you want, but I bet it isn't.
That is a list of strings and you almost certainly want a list of numbers. So ToExpression will help you.
You can then bundle this up and also verify the format using this.
As a general rule, I think making a copy of your notebook, editing the copy, and any needed data files, down to the point where it contains everything needed and nothing more for someone else who knows nothing about what is already in your head to be able to demonstrate exactly what the problem or the solution is, restarting Mathematica, or killing the kernel, evaluating all the cells in the notebook in order and then carefully copy-and-pasting all the notebook into a posting is the most likely way to get a good solution on the first try.
Are there at least a dozen different ways of accomplishing almost anything in Mathematica, including at least three that are completely incomprehensible? Yes.
|Apr19-11, 08:46 AM||#7|
Thank you so much for the advice and help,
I did manage to get it to work, by using SetDirectory and removing the "Table" specification from the Input command, it bring in the data in what I believe is a 65536x1 list (when I call Dimensions[omega], where omega is what I name the input, it gives me (65536,1), and I can get elements of the list via omega[[element index]]) so it looks like everything is hunky-dorie!
I don't know why it doesn't work without the SetDirectory command, or why I can't specify table (or array) when I use the setDirectory command, but in either case this works now.
Thank you for your help, BillSimpson I'm sorry I didn't end up using your algorithm, I appreciate the thought that went into it though, thank you for your consideration,
|Similar Threads for: Importing data into mathematica|
|Importing data in maple||Math & Science Software||1|
|Easy: importing a batch of data into MATLAB||Math & Science Software||5|
|Matlab - importing data from excel & interpolating||Programming & Comp Sci||1|
|Importing data into MATLAB||Math & Science Software||0|
|Techniques for successfully importing Excel data into Access||Computing & Technology||0|