Tag Info

New answers tagged

0

Here is how I would do it. First, import the data using Import. This is straightforward from the documentation, using either Excel or txt files, so for the purposes of this exercise, I'm going to generate the data in Mathematica instead. myD = MixtureDistribution[{2, 1}, {NormalDistribution[2, 2], NormalDistribution[2, 1/2]}]; For reference, here is ...


3

Possible cause: f = OpenWrite["test.csv"]; WriteString[f, "1,2,3\n\n4,5,6\n"]; Close[f]; FilePrint["test.csv"] Through[{Length, MatrixForm}@Import["test.csv", "Lines"]] Through[{Length, MatrixForm}@ReadList["test.csv", "Record"]] Readlist doesn't count a blank line (double line ending) as a "record" while Import does You can fix this with ...


2

A common approach to removing outliers is to use an order statistic filter. The simplest of these is the MedianFilter: x = data[[All, 1]]; ySmoothed = MedianFilter[data[[All, 2]], 5]; ListPlot[Transpose[{x, ySmoothed}]]


2

n = 20 (*even*) f = Interpolation[Transpose[{data[[All, 1]], Join[ data[[;; (n/2 - 1), 2]] , MovingAverage[data[[All, 2]], n] , data[[-n/2 ;;, 2]] ]}]] GraphicsColumn[{ListPlot[data], ListPlot[ Select[ data , Abs[f[#[[1]]] - #[[2]]] < .2 & ] ]}]


3

As you expect monotonic "smooth" behavior, a simple solution is to z-score the differences. diff = data[[All, 2]] // Differences; mn = Mean[diff] std = StandardDeviation[diff] (* 3 std is bad *) bad = Position[diff, x_ /; Abs[x] > Abs[mn + 3 std]] ListPlot[data, PlotRange -> All] ListPlot[data[[bad // Flatten]], PlotStyle -> Red] Show[%, %%] ...


4

The requirement that la + lc == 100 is simple to implement, just pass 100 - la to Fc, or use ModelP/.{lc->100-la} in the call to FindFit. For the other trouble, remember that N is a special function in Mathematica, so avoid ever using this as a variable. Using n instead, I tried ModelP = (2/q^4)*Re[((1 - Fc[q, lc, sc])*(1 - Fa[q, la, sa]))/ (1 - ...


11

data = Table[{i, i}, {i, 10}]; model = a + b x ^2; Unrestricted model: nlm = NonlinearModelFit[data, model, {a, b}, x] // Normal $ 0.0863422 x^2+2.17582 $ Model restricted to pass through {5,5}: nlmr = NonlinearModelFit[data, {model, (model /. x -> 5 ) == 5}, {a, b}, x] // Normal $ 0.0790502 x^2+3.02375 $ Picture: Show[Plot[{nlm, ...


1

Leonid provided the following demo in chat: the basic idea is to use R's read.table header management before coming back to Mathematica. file = URLSave["http://samplecsvs.s3.amazonaws.com/TechCrunchcontinentalUSA.csv"]; Needs["RLink`"] InstallR[]; RSet["testfile", file]; REvaluate["testdata <- read.table(testfile, header=TRUE)"]


2

Guessing/hoping that the following is not too far off from what you have in mind: lld = {{49.5671, 15.34, 50.0033, 17.9569, 100}, {48.7635, 16.0479, 49.5671, 15.34, 35}, {50.0033, 17.9569, 48.7635, 16.0479, 75}}; vertices = Join @@ (Partition[#, 2] & /@ lld[[All, ;; -2]]); edges = Property[UndirectedEdge[{#, #2}, {#3, #4}], EdgeStyle ...


1

This method will work with the ragged data array provided. Example 1 data = Import["henris_data_s3.csv"]; vnames = Transpose[data[[{1, 2}]]]; vnames[[99]] {"L1_INJ", "GWIR"} Above is the 'name' of the 99th record. Table[vdata[vnames[[i]]] = DeleteCases[Drop[Map[ Quiet[Check[Part[#, i], Null]] &, data], 4], Null], {i, Length[vnames]}]; ...


0

I don't know the answer to this question with a header of many lines and unique identifier specified by many lines. I am trying to create discussion about this in chat. Alternative solution with *ix tools Edit the original file to simpler form with instructions here so simplified datadump here and now read the simplified CSV into Mathematica where ...


1

I'm not sure if I understand completely what you want but let us show some properties of your data graphically. The data provided is a list of event data in the format {time instants of transition to another state, the state after transition} data = {{0.0, 0}, {2.0199, 1}, {3.3544, 0}, {6.2484, 1}, {7.0204, 0}, {16.6974, 1}, {17.4653, 0}, {33.1508, ...


2

OpenAppend itself does not cause newlines to be added. Only the export/write functions do. If you use WriteString, it won't add newlines. For example, s = OpenAppend["app.txt"] Do[WriteString[s, "a"], {5}] Close[s] results in a file containing aaaaa. You can include tabs using "\t".



Top 50 recent answers are included