Tag Info

New answers tagged

3

The table in the screenshot was produced by TableForm.


3

The closest thing to an R data.frame in Mathematica is a DataSet; http://reference.wolfram.com/language/ref/Dataset.html


1

Sometimes, the file size and number of frames of a bvh file can be very large, one might skip every other frames to reduce the file size and cut half of the number of frames. The example below, has 3602 frames and 2,559KB in size, one can cut it into half with the following codes: srcFile = "https://www.dropbox.com/s/j4k5f4vfqb592tw/Dance01.bvh?dl=1"; ...


2

Assuming that the example XML shown is representative, then we can exploit the fact the write and id attribute names are unambiguous within tekst elements: Cases[test , XMLElement["tekst", a_, c_] :> Sequence["write" /. a, Cases[c, ("id" -> i_) :> i, -1]] , -1 ] (* { "test1", {"AA-504771", "BB-59362", "CC-59362"}, "test2", {"AA-20210", ...


3

In this case what you want is simple/regular enough that you can define the XMLElement etc. as functions that return what you want inside a Block: Block[{XMLObject, XMLElement}, XMLObject["Document"] = #2 &; XMLElement["tekst", {"write" -> t_}, data_] := {t, Sequence @@ data}; XMLElement["lu", attr_, data_] := "id" /. attr; XMLElement[tag_, ...


2

The following can be used to extract the identifiers used in a given test case, which matches the "write" attribute of an individual XMLElement. Note that the attribute names "write" and "id" are hard-coded, which is not ideal. GetIdentifiers[data_, test_String] := Module[{elem, attr}, (*find test case*) elem = Cases[data, XMLElement[___, {___, ...


3

This seems to be a normal way to extract the data:- xml = XMLObject["Document"][{XMLObject["Declaration"] ["Version" -> "1.0", "Encoding" -> "UTF-8", "Standalone" -> "yes"]}, XMLElement["file", {"name" -> "filename.xml"}, {XMLElement["tekst", {"write" -> "test1"}, {XMLElement["relation", {"type" -> "co-synonyms", ...


1

A little integer and string hacking generates all and only the names required. Data = Table[s = ToString[j]; Import["C:\\Dropbox\\Sims\\datafile." <> StringTake[s, 2] <> "." <> StringDrop[s, 2] <> ".out", "Data"], {j, 200000, 300000, 1000}]


1

You could also use: data= Import["c:\\dropbox\\sims\\datafile.20." <> IntegerString[#, 10, 4] <> ".out" ]& /@ Range[1000]


3

You can use FileNames to get list of .out files data = Import[#, "Data"] &/@ FileNames["datafile.*.out", "C:\\Dropbox\\Sims\\", 1]


6

If you're using Windows you can use my MathMF package (see here). It is designed for frame-by-frame import and export of video files. The code would then look something like this: frames = FileNames["*.JPG", "C:\\Users\\Simon\\Desktop\\test images"]; << MathMF` MFInitSinkWriter["C:\\Users\\Simon\\Desktop\\test.wmv", 300, 300] ...


1

Here is a way that works for me (V9) by altering the normal pipeline of the Import/Export Framework. The usual disclaimer about using undocumented functionality applies. (* Setup *) ls55ImportSPDirectory[dir_String, OptionsPattern[]] := Module[{fname = dir <> "a.png", ret}, If[FileExistsQ@fname, ret = "File " <> fname <> " ...


55

TL;DR: package at the bottom of 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 official importer for "BVH" files, so ...


9

This is an unfortunate oversight on the part of Wolfram and would be of general interest, so I wrote a LibraryFunction in C (compiled using CreateLibrary) that will decompress data compressed using the Unix compress command (i.e. .Z files, compressed in the LZW format). Included are functions to extend Import and ImportString for the LZW format. You can ...


0

You can use the various FileName functions to get the result you want. The following function will import all the files in the folder ../images, modifies them with the function DoThings and exports them with the original file name extended by the last character of the file name. SetDirectory[".../images"]; Export[FileBaseName[#] <> ...


1

If you are looking for a function which takes in a filepath and generates a filepath to a file with nearly the same name, but with a duplication of the final digit of the base name, then you can use String pattern recognition like this: formatString = First@StringCases[#, x__ ~~ y_ ~~ ".jpg" :> x <> y <> y <> ".jpg"] &; ...


4

Just an alternative: f = Import["my_file.pdf", "Pages"]; MapIndexed[Export["page"<>IntegerString[First@#2,10,2]<>".png",#1]&,f] The use ofIntegerString allows left padding with zero which may useful in ordering files. In this case 2 -> 01,02,..99. This could be modified for large number.


4

Is there a way to convert the PDF pages into images within Mathematica Yes, just do f = Import["my_file.pdf", "Pages"]; and now f is a list, each is one page. Then use Export["f.png",f[[1]]] to export the first page as png Here is MWE SetDirectory[NotebookDirectory[]]; f = Import["my_file.pdf", "Pages"]; Export["page" <> ToString[#] <> ...


5

Classify actually supports a nice syntax for this: Classify[<|"class1" -> Import["class1/*"], "class2" -> Import["class2/*"]|>]



Top 50 recent answers are included