New answers tagged

2

The WriteString in your loop form should be: WriteString[path, 0.01*i, " ", 1/((y[30]^2 + y[30 - Pi/2]^2)) /. First@s, "\n"] This gives you no { } in the file and Imports properly. You could also use Write: Write[path, 0.01*i, OutputForm[" "], 1/((y[30]^2 + y[30 - Pi/2]^2)) /. First@s] That said its usually preferable to generate ...


0

Here is a very hack-ish way of coloring each residue sequentially. The trick is in constructing a Blend[] function where the color corresponding to each residue appears twice in the first argument. A slight shift is apparently needed to match up the colors, even if only approximately. n = StringLength[First[Import["ExampleData/1PPT.pdb", "Sequence"]]]; ...


0

This seems to work as intended: style = CurrentValue[EvaluationNotebook[], StyleDefinitions]; Export["001_sty.nb", style, "Text"]; and style = Import["001_sty.nb", "Text"]; SetOptions[ EvaluationNotebook[], StyleDefinitions -> ToExpression @ style ]; Anyway, I think that a crash or an internal self test error, when a simple error message ...


3

After experimenting with the free multiplatform tool GPSBabel (http://www.gpsbabel.org/) and with the Python module Fitparse (https://github.com/dtcooper/python-fitparse), I can share the following: If you want latitude and longitude only, GPSBabel is fine. It converts the spatial coordinates in a Fit file into GPX format, which Mathematica can import. ...


1

OK, I found a second way. Like kglr's solution, this one also uses AssociationThread, but applies it only once: makeDataset[columns_, columnLabels_] := Module[{labeledColumns, records}, labeledColumns = AssociationThread[columnLabels, columns]; records = Transpose[labeledColumns, AllowedHeads -> All]; Dataset[records] ]; The importer can be ...


4

columnames=CharacterRange["a","h"]; data= RandomInteger[9,{20,8}]; ds=Dataset[AssociationThread[columnames->#]&/@data]


0

I absolutely support JasonB's suggestions, especially hdf5 seems a good format for such data when you want to be able to read with other software. But for the case where you only need to write and read with Mathematica, I think the MX format at least needs to be mentioned as well: it is by far the easiest and fastest way to store arbitrary expressions (not ...


0

If you plan to use your data in MMA only you can do a = RandomReal[1, {1000, 3, 3}]; Dimensions[a] a >> testExport.dat b = << testExport.dat; Dimensions[b] a == b


3

You can export as a MATLAB .mat file if your array has less than 4 dimensions, rand = RandomReal[1, {1000, 3, 3}]; Dimensions@rand rand[[454, 1, 2]] Export["random.mat", rand]; (* {1000, 3, 3} *) (* 0.786307 *) When you import it again, you have the same dimensions and the elements are the same rand2 = Import["random.mat"]; Dimensions@rand2 rand2[[454, ...


0

I figured it out. data = Import[ "/Users/myname/Documents/foldername/filename.txt", "Table"] Total[data, {1}] Part of the error was that I had an empty row at the end of my text file.


1

You need Import, Part (i.e. [[...]]), probably Span (i.e. ;;), and Total. Import the data: data = Import["path\to\yourdatafile.txt", "Table"]; Sum all entries in the first column: Total@data[[All, 1]] Sum entries in the third column and in the second to third row: Total@data[[2 ;; 3, 3]] Sum entries in column 2, rows 1 and 3: Total@data[[{1, 3}, ...


6

The sample rate is the second element in solo. The first element (i.e., solo[[1, 1]]) is the waveform data. solo = Import["ExampleData/rule30.wav"]; solo[[1, 2]] 44100


9

One can also use Import[] to directly query the *.wav file's sample rate, like so: Import["ExampleData/rule30.wav", "SampleRate"] 44100


8

solo = Import[ "ExampleData/rule30.wav" ] Cases[solo, (SampledSoundFunction | SampledSoundList)[__, r_] :> r, Infinity][[1]] 44100


5

If you don't want to save the file to the disk, you can use stream to do the trick. You can import the zip file as a string from the web and convert it to stream, which then can be treated as a file. For example: url="http://www.retrosheet.org/gamelogs/gl2015.zip"; str=Import[url, "String"]; filename = First@Import[StringToStream[str], "ZIP"]; ...


5

The syntax you use is wrong. There is no import element called "P" for the MAT format. Take a look at the documentation: it lists the allowed elements: "Elements", "Rules", "Options", "Data", "LabeledData", "Comments", "Labels". You probably want "LabeledData", so use Import["file.mat", {"MAT", "LabeledData"}] or alternatively Import["file.mat", ...


2

This turned out to be pretty simple, using ClickPane to capture the clicks, and MousePosition so that you can see the current coordinates. After running the code below, and placing your mouse over the plot, the coordinates are displayed above the plot. After clicking, the coordinates you click are added to the list pts. This bypasses any interaction with ...


1

You might try to use Locatorfor this purpose. Try this: coord = {}; DynamicModule[{pt = ImageDimensions[im]/2 // N}, Column[{ Show[{ image, Graphics[Locator[Dynamic[pt]]] }], Dynamic[pt], Button["Get coordinates", Clear[coord]; coord = pt] }] ] where ┬┤image` is the name of your image and coord is the global variable. You ...


0

THIS IS AN EXTENDED COMMENT RATHER THAN AN ANSWER. $Version (* "10.4.1 for Mac OS X x86 (64-bit) (April 11, 2016)" *) plt = Plot[Sin[x], {x, 0, 2 Pi}] Export["Desktop/myfile.eps", plt]; plt2 = Import["Desktop/myfile.eps"] The tick labels are missing although they appear when the eps file is opened in another application (e.g., Preview). ...


3

Okay, so this is what it looks like with standard coloring of the residues: Import["ExampleData/1PPT.pdb", ColorFunction -> "Residue"] But now, if we want to change the residue colors, we need to change the value of a certain internal color list called Graphics`MoleculePlotDump`residueColorRules residuelist = {"Gly", "Pro", "Ser", "Gln", "Pro", ...


0

I can propose a more general solution. It is based on regular expressions (or here, string patterns). The idea is to look for the shortest strings in the file that begins with double-quote, ends with double quotes, does not contain any double quote, but can contain one or many EndOfLine. As it is a CSV, there are comma before the double-quote (thus, this ...


1

You need to evaluate the cells. You can evaluate the current cell by using "Shift+Enter". For an introduction to evaluation, here are some helpful references: Interactive Usage page of The Wolfram Language: Fast Introduction for Programmers. Practicalities of using the Wolfram Language from An Elementary Introduction to the Wolfram Language by Stephen ...



Top 50 recent answers are included