The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

89

TL;DR: A package (Mathematica v10) can be found at the very bottom of this post. UPDATES 6: Tiny update: Import can now use the ".bvh" extension to determine the import type. The code that does this is ugly, but I don't see any other way at the moment. out = Import["C:\\Female1_C03_Run.bvh"] 5: Added error checking and registered the package as an ...


76

I think probably the cleanest way to do this (at least, if you have only a single string, or are faced with a separate string for each number you wish to convert as a result of some other process) is to use the undocumented function Internal`StringToDouble, i.e.: s = "1.23e-5"; Internal`StringToDouble[s] which gives: 0.0000123 However, if you are trying ...


70

I started with the image you provide and called it img. This solution isn't perfect but it might serve as a starting point. Get some known points: I right clicked the image and selected "Get Coordinates". I then clicked as closely as possible to the origin, and the points {0,1.3} and {10.,.82}. On Windows hold Ctrl+C to copy those points. And then Ctrl+...


60

Here the contours of a method to do this half-automatic selection you are looking for. It is heavily based on an example on the ImageCorrelate doc page of Waldo fame. First, you interactively select an example of the plot marker you want to look for: img = Import["http://i.stack.imgur.com/hhPr9.png"]; pt = {ImageDimensions[img]/4, ImageDimensions[img]/2}; ...


54

Have a look at FileNames: files=FileNames["*.pdf", NotebookDirectory[]] {"a.pdf","b.pdf","c.pdf"} will get you a list of all files in the directory where your notebook resides (of course you can choose any path) that match "*.pdf". You can then import the files like this: Import[#]&/@files or if you want certain files (look at the help for Part ...


43

Let me emphasize what IMO are the key-points in the image-processing here. First of all, if your images are not so bad there is no requirement to manually find the inverse transformation. What you should try is (as @kguler already mentioned) a Hough-transform which detects lines. An equivalent filter in Mathematica is given by ImageLines. So what you do is, ...


42

Assuming you haven't placed your variables in a non-standard context you can save them all at once using DumpSave's second syntax form, which saves everything in the indicated context. Quit[] (* start a fresh kernel *) x = 1; (* define some symbols *) y = 2; z[x_] := x^2 Names["Global`*"] (* Check they're there *) (* ==> {"x", "y", "z"} *) (* Save ...


38

The following is something I made while trying to solve another (similar) problem (*FindCurvedPath Replacement*) ClearAll[findCurvedPath2, findClosedPath2]; findClosedPath2[inptList_, cutoff_] := Append[#, #[[1]]] &@ findCurvedPath2[inptList, cutoff] findCurvedPath2[inptList_, cutoff_] := Block[{ ...


37

I think you can use Names["Global`*"] to get the name: a = RandomReal[{0, 1}, 10]; SetDirectory[$TemporaryDirectory]; DumpSave["1.mx", a]; Quit[] SetDirectory[$TemporaryDirectory]; << 1.mx Names["Global`*"] (*{"a"}*)


34

The first thing we need to do is to determine how the initial page assembles the parameters and transmits the request to the server. One way to do this would be to open the initial page using the developer tools in the web browser. But since this is a Mathematica forum, let's try to use the tools it makes available to us. We could load the page text and ...


34

You can export to the MX format: Export["out.mx", data, "MX"] Be aware that this format is not portable between different computer architectures (e.g. 32/64 bit). Import using data = Import["out.mx"]; This is the fastest available format in Mathematica. Most likely you can't do better than this, unless you write an interface to a specialized external ...


33

64-bit Windows only Note for Mathematica 11.3: There is a potential conflict between MathMF and the built-in MediaTools package. See here for details and here for an example of how to use MediaTools in place of MathMF.   Note for Mathematica version 10: The Wolfram Library has been updated in version 10 and you will need to recompile the MathMF DLL. ...


33

In a post about automated image uploading Arnoud Buzing describes an undocumented and unsupported POST method. It looks like this: xml = Import[url, "XML", "RequestMethod" -> "POST", "RequestParameters" -> {"key" -> key, "image" -> image}]; Note: at the time of this answer I was using V8. Since the arrival of URLFetch in V9 I ...


33

For a one-off read you can Skip a number of records: str = OpenRead["test.tsv"]; Skip[str, Record, n - 1]; data = ReadList[str, {Record, Number, Record}, 100, RecordSeparators -> {"\t", "\n"}]; Close[str]; If you will be reading from the same file many times, it may be worth building an index you can use with SetStreamPosition str = OpenRead["test.tsv"]...


33

Get all the files here. .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 SDK\V2.5\lib\DocumentFormat.OpenXml.dll (for Formulas in the MathML ...


32

You can use the binary format to speed up the process: python side import numpy as np array = np.random.rand(100000000); array.astype('float32').tofile('np.dat') Mathematica side data = BinaryReadList["np.dat", "Real32"]; // AbsoluteTiming (* {2.56679, Null} *) data // Dimensions (* {100000000} *)


31

I recommend that you import as an XMLObject, which represents structured XML data in a Mathematica-based format. info = Import[ "http://area51.stackexchange.com/proposals/4470/martial-arts", "XMLObject"]; You can access the parts of xml using Mathematica patterns, like so: labels = Cases[info, XMLElement[ "div", {"class" -> "site-health-...


30

Your problem is that you've got a slight misunderstanding of the different types of items that ReadList can read. That's OK, it can be a little confusing. To begin with: String, Number, Expression, etc. are not sub-types of Record. They are all separate types with their own rules for how they are read. The RecordSeparators option is only applied to ...


28

Using the (deprecated but easy) API documented here, result = Import[ "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=fuzzy%20monkey", "JSON"] Import["url" /. ("results" /. ("responseData" /. result))[[1]]] If you hit the service too many times, it'll lock you out for a while. Here's another example that gives the 24th-32nd results:...


28

Mathematica is interpreting c as a currency marker. This is controlled by the "CurrencyTokens" import option for "Table". The default setting for "CurrencyTokens" is {{"$ ", "£", "¥", "€"}, {"c ", "¢", "p ", "F "}} so this also happens with the letters p or F. The workaround is ImportString["123c", "Table", "CurrencyTokens" -> None] (* {{"123c"}} *) ...


27

If you use Import/Export to load/save .mx files, instead of DumpSave, then the variable does not get embedded in the file, and you can assign it to any variable of choice in the new session. x = RandomReal[1, {100, 100}]; Export["~/tmp.mx", x]; y = Import["~/tmp.mx"]; x == y (* True *)


27

Well, I suspect this question will get closed because it is a bit broad, but I've played around with image tracking and thought I'd show what I've done in case it's helpful. I was interested in learning some physics, and have the following video: To do the tracking, I smoothed out the images and converted them to black and white, which allows for the ...


26

Certainly. There have indeed been some changes to certain tags in the 2.1 API and also to the method to sort out how many pages to import. And, since we are now a full site under StackExchange, the server has changed and a site parameter was necessary. I did a bit of clean-up, hardened the code a little to accommodate connection failures, made the basic ...


25

The technique is mentioned in one of Wolfram CDF virtual conference talks (See the course: Developing Real-World CDF Applications), as well as being used in a lot of CDF examples (for instance, the slideshow at the beginning of this example) but I will repeat it here, with some improvement. Recompressing images with better compression (Note: While writing ...


25

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 "...


24

I've implemented a java program using the JavaMail API to only fetch unread emails from a particular user (and mark it as read). This will allow you to periodically get emails from your ship traffic service. This is inspired by this blog post on Stephen Wolfram's email analytics. 1. Java code to fetch unread email from a sender Below is the java code, ...


24

With this function a random integer is inserted in the e-mail address (gmailuser@gmail.com becomes gmailuser+randominteger@gmail.com) and then the hash value is computed. The hash value is used to get the corresponding identicon from the Gravatar website. This approach can address also some privacy concerns. generatePic[email_] := Module[{emailparts, ...


24

This seems to work: Import["data.csv", "table", FieldSeparators -> ";"] Should be Import["data.csv", "Table", "FieldSeparators" -> ";"] See help for "Table" element (ref/format/Table), specifically Options section.


23

I don't know if you can persuade Import to return the correct durations, but luckily the format of .gif files is pretty straight forward so it's not that hard to extract the correct durations manually from the raw data. In an animated gif the frame durations are stored in a so called Graphic Control Extension or GCE preceding each frame. A GCE starts with ...


23

If the data are comma-delimited and saved as myfile.txt then data =Import["C:\\Users\\md\\Desktop\\myfile.txt", {"Data", {All}, {1, 3}}]; imports columns 1 and 3, giving: (*{{"a1", "a3"}, {"b1", "b3"}, {"c1", "c3"}, {"d1", "d3"}}*) For comparison, Import["C:\\Users\\md\\Desktop\\myfile.txt", {"Data"}] gives (*{{"a1", "a2", "a3", "a4", "a5"}, {"b1", "...


Only top voted, non community-wiki answers of a minimum length are eligible