Hot answers tagged

10

If you write an HTML img tag like this: <img src="url/to/image.jpg"> then the image will be downloaded directly upon page load. Some frontend developers don't like this as they think it's more important to quickly show the bulk of the page. The images can come later. So what they did in this case was writing <img data-src="url/to/image.jpg"> ...


5

ToExpression is very fast for correct Mathematica syntax input. So the key idea is to create an input string for ToExpression that delivers the expected result for the huge string database in one go: StringData // Extract[{All, 2}] // StringRiffle[#, {"{{", "Nothing},{", "Nothing}}"}] & // ToExpression The odd looking "Nothing}" in ...


4

Here's a solution using the "FieldSeparators" option for the "Table" import format: Import[ "exo_data.txt", "Table", "FieldSeparators" -> {"\t"}, "RepeatedSeparators" -> False, HeaderLines -> 1 ] (* { {"11 Com b", 19.4, 0.231, 2.7}, {"11 Oph b", 21, "", 0.0162}, … } *) Note the use of "RepeatedSeparators"->False to ...


4

strtolist2 = Map[FromDigits, StringSplit[StringData[[All, 2]], ","], {-1}] strtolist3 = IntegerPart @ Map[Internal`StringToDouble, StringSplit[StringData[[All, 2]], ","], {-1}]; strtolist3 == strtolist2 == strtolist True Both are about twice as fast as For loop with IntegerPart/@Internal`StringToDouble/@...


3

Not a complete answer, just some thoughts as a way to go ... First, I would get a list of all Imported files: files=(Flatten@Import[fullpath <> "S__"<>StringTake["_"<>ToString[mic],-2]<>"_Take01_M24.wav", "Data"] &) /@ Range[82]; This is your command Import and your mic changed to Slot going from 1 to 82. Next, cutting ranges: ...


3

Try mydata2 = Import["gstar.xlsx", {"Data", 1, All, ;; 2}]; Interpolation[mydata2] {"Data", sheetlist, rowlist, columnlist} specification extracts data from sheets in sheetlist the rows in rowlist and columns in columnlist. So {"Data", 1, All, ;; 2} says "get the array of data in columns 1 and 2 form all rows of sheet 1". See XLSX >> Import ...


3

The implementation of $ScriptInputString in wolframscript is buggy. I have found that providing !cat to an import function (ReadString, Import, ...) is a more stable way of reading from stdin. When using wolframscript, this approach only works in cases where $ScriptImportString doesn't, presumably because the stream is already consumed otherwise. A ...


3

It seems that using SemanticImport with tab as a delimiter does what you want: SemanticImport["~/Downloads/Exo_data.txt", Delimiters -> "\t"]


3

Here is one option using text manipulations. data = Import["test.dat", "Text"] "{x1,x2, x3, x4, x5, x6, x7,x8} {y1,y2, y3, y4, y5, y6, y7,y8}" data2 = "{" <> StringReplace[StringReplace[data, WhitespaceCharacter -> ""], "}{" -> "},{"] <> "}" "{{x1,x2,x3,x4,x5,x6,x7,x8},{y1,y2,y3,y4,y5,y6,y7,y8}}" Export["test.txt", ...


3

In Mathematica 12 we have renamed these private functions. The following code works in 12.0: In[1]:= file = URLSave["http://mirrors.standaloneinstaller.com/video-sample/\ Panasonic_HDC_TM_700_P_50i.avi", "c:\\tmp\\sample.avi"] Out[1]= "c:\\tmp\\sample.avi" In[2]:= Needs["MediaTools`"] In[3]:= MediaTools`Private`$MFInitVideoReader[file] Out[3]= True ...


3

You may use the NDSolve Components and Data Structures tutorial to control the memory usage and save down the state of intermediate runs. Initialise the NDSolve`StateData for the complete range you need to create solutions. Below is done for 0 <= t <= 30 and I will iterate in chunks of 10. ndsStateData = First@NDSolve`ProcessEquations[ { D[u[...


2

Suppose … is the path to the file (You can easily obtain the path by Ctrl+c and Ctrl+v on Windows ) then: Import[…, "Table"] Or ReadList[…, Real, RecordLists -> True] The latter should be faster.


2

The following throws some inconsistency warnings, but appears to work (i.e., no obvious discontinuities at the seam). Also, I did not change the boundary condition, but I fed the final condition of the first solution to the "initial" condition of the second solution. uif1 = NDSolveValue[{D[u[t, x], t] == D[u[t, x], x, x], u[0, x] == 0, u[t, 0] == Sin[...


2

I recommend the use of FileNameJoin for dealing with OS full file path names. It is system indecent and you don't have to worry about such things as backslashing or directory name delimiters. Both of the following work. gdoubleprime = Import[FileNameJoin[{$HomeDirectory, "Downloads", "data.csv"}]]; gdoubleprime = Import["data.csv", Path -> ...


2

This is how I import files when I'm not sure of the path name. Open the terminal by typing command-Space then terminal. Then drag the file into the terminal window. You will see something like: /Users/yourName/Documents/Papers/fileName.csv Highlight this and copy paste into Mathematica: data = Import["/Users/yourName/Documents/Papers/fileName.csv"] and ...


2

One way is gdoubleprime = Import["/Users/gag/Downloads/data.csv"]. However this will only work for the user gag. A more general way is to use the home directory and downloads with gdoubleprime = Import["~/Downloads/data.csv"]. You should also consider one of a couple of possible general policies for data files. The first is to put them into the same ...


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