Tag Info

New answers tagged

3

Using BlockStream from this answer and the techniques from this answer, this is how I would load an LTSpice using the sample as a template: ClearAll[toRule, skip]; Options[toRule] = {Trim -> True}; toRule[s_String, opts : OptionsPattern[]] := toRule[s, ":", opts] toRule[s_String, del_, opts : OptionsPattern[]] := Rule @@ If[OptionValue[Trim], ...


3

The following works : fileFullName = (*to be defined by you*) page = 1; ti00 = Import[fileFullName, "Text"] // StringReplace[#, {Except[StartOfString] ~~ "Title" -> "TitleTitle"}] & // StringSplit[#, Shortest["Title: " ~~ x : ___ ~~ "Title"] :> "Title: " <> x] & // (#[[page]] &) // ...


1

You'll want to use Algorithm R for reservoir sampling to get a truly random sample (as opposed to periodic) with only one scan of the input and no need to know the length of the input in advance. Basically, you take the first items and then randomly replace them with decreasing frequency as you complete the scan. sampleSize = 100; stream = ...


4

Use Save - it works like DumpSave, except the output is not binary encoded, and is transportable from system to system, (different operating systems / Mathematica versions, to an extent). out[] := Cases[DownValues[out], _String, Infinity] out[ToString[DataStep1[[l, 3]]]] = outNR Save["Renegotiation.sav", out] << Renegotiation.sav Docs: ...


2

For Example: (Let's define some data*) t20 = Range@10; J20 = RandomReal[{0, 1}, 10]; tabt20 = Transpose[{t20, J20}]; (*better than your Table[] !*) Intt20 = Interpolation[tabt20]; (*Interpolate*) Intt20[3.3] (*calc it at some point *) Plot[Intt20[x], {x, 1, 10}] (* plot it *)


1

I'd recommend rethinking your data structure a bit. How about defining lists like: data[[i]] = {{DataSetName1, m1, m2, m3,m4},{DataSetName2, m1, m2, m3, m4},...} for i=1 to however many pieces of data you have. Then the corresponding time[[i]] =[5, 10, 20, 1440] and etc for all the different items. Now you can just index through the i, instead of ...


1

I am not certain where your trouble lies, but since you mention ToString and ToExpression you're surely making this harder than it needs to be. Let me show you a couple of methods to format your data in the way I think you intend. Sample data: dat = {{"cat", 8, 18, 9, 1}, {"dog", 19, 15, 15, 7}, {"fox", 7, 10, 9, 20}, {"bird", 17, 10, 1, 5}, ...


2

A simplistic,if slightly inefficient, solution might be: data = Import[#,"Table"][[39;;-3]]&/@Filenames[]; Other options might involve, 'Cases', 'Choices', Drop, Take. For example: data = Drop[Drop[Import[#,"Table"],38],-2]&/@Filenames[]; If you are using a Linux derivative or something like cygwin on Windows, then this is an efficient ...


3

You can wrap your Skip and Readlist in a Module and make it a function: importfile[name_] := Module[{strm, mydata}, strm = OpenRead[name]; Skip[strm, Record, 38, NullRecords -> True]; mydata = ReadList[strm, Number, 7500*3, RecordLists -> True]; Close[strm]; mydata ] importfile@"f1-Oxs_TimeDriver-Magnetization-000000-0000028.omf" This ...


3

Via @chuy and @rcollyer with sequential skipping and reading of records, and without backtracking. ( If[# != 1, Skip[s, Record, # - 1], Null]; ReadList[s, Number, 2]) & /@ Differences[p~Prepend~0] List p of lines you want to read, sorted; eg. some random ten from a hundred: p = Sort[RandomSample[Range[100], 10]]; Your file opened as a stream, ...


4

Surely not the fastest or ideal solution, but this should work (it assumes that you have two numbers in each row): randomline[str_InputStream, num_] := ( SetStreamPosition[ str, 0]; Skip[str, Record, num-1]; Read[str, {Number, Number}]) str = OpenRead["data.txt"]; Now, if you have 2000 lines and want 100 random samples: Map[randomline[str, #] ...


1

You are correct: there is a distinction between the string "a" and the symbol a, and that is presumably why your approach doesn't work. Whenever pattern matching doesn't work as expected it is a good idea to look at FullForm or at least InputForm to see what causes the problem. Here is the imported data (I prepared an excel file as you described and import ...


1

If you are working in version 9, there is a function called ImageFileFilter which applies any function f to all the pixels of an image, without reading the whole image into memory. So if your data happened to be an image your problem would be solved. But of course an image is just an array of numbers, so another strategy you could consider would be to ...


3

To Solve your example: Calculate the mean and the mean square deviation of the irregular partition of lengths n={3,2,5} of the list y={3,5,8,7,9,4,6,2,1,5}; (* irregular partitions of lists based on Nest *) iPartition[x_, lengths_] := First@Nest[{Append[First@#, Take[#[[2]], First@Last@#]], Drop[#[[2]], First@Last@#], Rest@Last@#} &, {{}, x, ...



Top 50 recent answers are included