Tag Info

New answers tagged

2

For simply saving numbers or lists to file, I personally prefer to use Put/>> and PutAppend/>>> to store data, and ReadList to retrieve it. For instance: (# >>> "file.dat") & /@ {1,2,3}; ReadList["file.dat"] (* {1,2,3} *) (# >>> "file.dat") & /@ {1,2,3,4,5}; ReadList["file.dat"] (* {1,2,3,1,2,3,4,5} *) You could ...


5

Open the file with OpenAppend not OpenWrite. Any Writes will then append to the file not overwrite.


0

A general solution for importing .csv files is the use of StringReplace. First import the data dataRaw = Import["......KlimaLoggPro4.csv"]; dataRaw // Length 18133 E.g. the following two lines come from a climate logger. The second line is the data and is of course available several thousand times. As you can see, it is completely gobbled. ...


8

Taking user5601's suggestion to do a little demo, I quickly whipped this up as an example of ProcessLink being used to do non-trivial communication between Mathematica and an external program, but with much less ceremony than using ProcessLink or MathLink. Let's take this little Go program: package main import "net/http" import "bufio" import "os" import ...


1

If you data is labelled "blah.xls" then your input should be Import["blah.xls"] Just make sure the data file is in the correct directory.


2

I would read the csv file as a stream. It's very quick. First, I use the following function to look for specific lines. ClearAll[readLine]; readLines[stream_, search_?StringQ] := With[{stro = FindList[stream, search]}, ImportString[StringJoin[Riffle[stro, "\n"]], "Table"] /; stro =!= {}] Then I open a stream: file = "data.csv"; str = ...


6

Both have advantages and disadvantages. Importing XLS is done using a Java-based application. In my experience, it is terribly slow and eats up enormous amounts of memory to the extent that it blows up your Java heap space, requiring a manual adjustment of this heap space (quite often to no avail). It happens to me all the time that a data structure that I ...


17

Get all the files here: http://JeremyThompson.net/Rocks/Mathematica/MmaWord.zip .Net Mathematica Word Library You will need to use a Microsoft library to open word documents. In a language such as .Net it is very easy; just open Visual Studio, reference the Microsoft.Office.Interop.Word .Net DLL (for Words) and the C:\Program Files\Open XML ...


1

Leonid provided the following demo in chat: the basic idea is to use R's read.table header management before coming back to Mathematica. file = URLSave["http://samplecsvs.s3.amazonaws.com/TechCrunchcontinentalUSA.csv"]; Needs["RLink`"] InstallR[]; RSet["testfile", file]; REvaluate["testdata <- read.table(testfile, header=TRUE)"]


1

This method will work with the ragged data array provided. Example 1 data = Import["henris_data_s3.csv"]; vnames = Transpose[data[[{1, 2}]]]; vnames[[99]] {"L1_INJ", "GWIR"} Above is the 'name' of the 99th record. Table[vdata[vnames[[i]]] = DeleteCases[Drop[Map[ Quiet[Check[Part[#, i], Null]] &, data], 4], Null], {i, Length[vnames]}]; ...


0

I don't know the answer to this question with a header of many lines and unique identifier specified by many lines. I am trying to create discussion about this in chat. Alternative solution with *ix tools Edit the original file to simpler form with instructions here so simplified datadump here and now read the simplified CSV into Mathematica where ...


3

Copy/paste from the excellent BVH package by @Sjoerd C. de Vries: The code in this question (Registering/detecting an importer by file name extension) did not work. Neither did the answer. Wolfram support could not provide a more elegant solution so far. We use a trick here. In fact we don't have any options, but we need to add the option part to the ...


0

This works for me with large data (1E6 points) in Ver 8.0.1: test = Import["scope_29_1.csv", "Data"]; test2 = ToExpression[Drop[test, 2]]; "Data" forces mathematica to convert 1.734E-003 into 0.001734 but keeps as string because the first 2 lines contains names. "Drop" Keeps the first non-numerical lines out.


1

Import["binary.txt"] in this case is equivalent to Import["binary.txt", "Text"] not to Import["binary.txt", "String"] Documentation states that Import["binary.txt"] "reads a text file, taking the character encoding to be "UTF8" by default." Whereas for format "String" documentation states that "imports a raw sequence of bytes and returns them as a ...


1

I think that the reason is that -- depending on the format -- Import does either use external programs, java libraries via JLink or the frontend for imports of most "nontrivial" formats. Only some -- mainly simple ascii or plain binary -- formats and of course mathematicas own syntax are directly "imported" with pure kernel functionality. As you correctly ...


0

For some reason I'm not aware of, Mathematica has trouble using the Import function when the kernel is first starting up. Perhaps it loads the init.m file before it loads the definitions of all the different file types. But apparently, it knows hot to Get from a properly formatted file. If I run Export["/home/jason/temp.m", Table[{n, 2 n, 3 n}, {n, ...



Top 50 recent answers are included