Tag Info

Hot answers tagged

20

Some function definitions first. AkimaInterpolation[] stolen from here (Thanks JM, wherever you are!): AkimaInterpolation[data_] := Module[{dy}, dy = #2/#1 & @@@ Differences[data]; Interpolation[Transpose[{List /@ data[[All, 1]], data[[All, -1]], With[{wp = Abs[#4 - #3], wm = Abs[#2 - #1]}, If[wp + wm == 0, (#2 + #3)/2, (wp #2 + wm ...


7

To import the first 100 rows of the file you can use Import["myfile.data", {"Data", Range[100]}] and to import the last 100 rows Import["myfile.data", {"Data", -Range[100]}] or Import["myfile.data", {"Data", Range[-100,-1]}]


5

I think the SelectFirst approach is probably one of the easiest to read but just for fun here are a couple of other solutions. I'll start by generating a sample table t0. t0 = RandomReal[{0, 1}, {10^5, 151}]; r0 = t0[[50000]]; Applying your method with Select is pretty fast. (Note that SelectFirst is faster for the unique case proportional to the position ...


5

The approach to address the encircling areas will be using the Graph fucntionality available in Mathematica. There are some null values in the dataset so we'll remove them in the new dataset piracyLocations. asamjson = Import["http://msi.nga.mil/MSI_JWS/ASAM_JSON/getJSON?typename=\ DateRange_AllRefNumbers&fromDate=19900101&toDate=20140801", ...


4

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 ...


4

For a set of data $\{t_i,A(t)\}$ its possible to define a continuous function, properly scaled, that is the Fourier transform of the data set. 1/Sqrt[n] Sum[y[[r]] Exp[(2 \[Pi] I)/n (r - 1) (s n dt)], {r, n}] Then an implementation for the absolute value of the Fourier transform could be: cxyFtM[d_, s_] := Block[{n, t, y, dt}, n = Length[d]; t = ...


3

I encourage you to use the following command: Import["file_name.txt", "Table"][[All, ;;100]] It works by default with any structured data, while "Data" doesn't. And what's more important - surprisingly it works much faster than importing separated rows or columns - time difference could be the 10-100 times for huge files. And eventually it's much easier ...


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[%, %%] ...


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 & ] ]}]


2

Your data: data = {{0.067, 0.423}, {0.30, 0.408}, {0.60, 0.433}, {0.25, 0.3512}, {0.37, 0.4602}, {0.44, 0.413}, {0.60, 0.390}, {0.73, 0.437}, {0.8, 0.47}}; errors = {0.055, 0.0552, 0.0662, 0.0583, 0.0378, 0.080, 0.063, 0.072, 0.08}; ErrorListPlot[Transpose[{data, ErrorBar /@ errors}], PlotRange -> {0, 1}] Assume that the errors are distributed ...


1

Perhaps this is enough for you: d1 = Transpose[{#[[1]] - #[[1, 1]], #[[2]]} &@ Transpose@Select[data, #[[2]] > 0 &]]; nlm = NonlinearModelFit[d1, c PDF[BetaDistribution[3, b], x], {b, c}, x]; Plot[nlm[x], {x, 0, .003}, PlotRange -> All, Epilog -> Point@d1] Another option: nlm = NonlinearModelFit[d1, c PDF[MoyalDistribution[.0002, b], ...


1

Use the function 'take' for example list = Import["myfile.data",{"Data",{1,2,3},All}]; Take[list1, 100] you will get the first hundred values Take[list1, {100,200)] you wil gett the values hundred until twohundred


1

Although it is not clear from the Mathematica documentation, it appears that in the default Automatic method FindClusters[] may use an iterative algorithm to partition the data set into k clusters, compute a global merit function (such as sum of inter-point distances), then randomly select a point from one randomly selected cluster and assign that point to a ...


1

It's FinancialData["NYM:NGG15"] but most properties aren't available


1

The following approach will address the requirement Areas where the histogram is more than some threshold value... asamjson = Import["http://msi.nga.mil/MSI_JWS/ASAM_JSON/getJSON?typename=\ DateRange_AllRefNumbers&fromDate=19900101&toDate=20140801", "JSON"]; Needs["GeneralUtilities`"] asamdataset = Dataset[ToAssociations@asamjson]; asamdataset = ...


1

It is not clear to me what is the difference between FindFit and NonlinearModelFit. But NonlinearModelFit help says: And FindFit says In this case, they both indeed produce the same fit, hence both are doing least squares model = a + b/(c*x^2); nlm = NonlinearModelFit[data, model, {a, b, c}, x]; nlm["ParameterTable"] nml2 = FindFit[data, model, ...


1

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 ...



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