Tag Info

Hot answers tagged

12

To reduce the number of points, I'd use Interpolation: f = Interpolation[Transpose@{x,y}, InterpolationOrder->1]; Plot[f@x,{x,0,100}]


12

This filters out your points by their EuclideanDistance. I think it makes a pretty good job preserving the curve's features with very few points: rx[n_] := Accumulate[Prepend[RandomVariate[ExponentialDistribution[1000], n], 0]] ry[n_] := Accumulate[Prepend[RandomVariate[NormalDistribution[0, .001], n], 0]] c = Transpose[{rx@#, ry@#}] &@100000; t = ...


11

Here is a modified version of belisarius' answer I ended up using. Instead of using the euclidean distance to find out if two points are close to each other I set a fixed rectangle in an area and collapse it into a line. For instance, consider the same example. rx[n_] := Accumulate[Prepend[RandomVariate[ExponentialDistribution[1000], n], 0]] ry[n_] := ...


9

As I said in my comment, the Douglas-Peucker algorithm is a standard method for simplifying polygonal curves. This demonstration by Mark McClure contains a Mathematica implementation. Since he is a user on this site, I feel like he deserves the points for this answer. Nevertheless, in the interests of having an answer here, and hoping this falls under fair ...


7

You can decompress on the Mathematica side easily. Compressed MySQL reply has the following format: first four bytes are size of uncompressed data (lowest byte first) the rest is the string compressed with deflate algorithm (zlib library) Here is an example of a reply: {10, 0, 0, 0, 120, 156, 243, 72, 205, 201, 201, 87, 240, 170, 112, 82, 4, 0, 19, ...


7

The documentation is misleading here. On one hand, the only export option is "Append" which can be found under the Options tab. On the other hand, the general documentation reads I really wonder, why it is necessary to put Import only behind an option value when "DataEncoding" isn't an export option at all. Anyway, I have the same behaviour in MacOSX ...


4

Here is a way to only uncompress elements that have been compressed. Note that using Mathematica's Compress returns a string starting with <number>:, so we need to Uncompress only those elements that are strings and start with that. Clear@uncompress uncompress[s_String] /; StringMatchQ[s, DigitCharacter ~~ ":" ~~ ___] := Uncompress@s uncompress[x_] ...


3

In version 7 halirutan's export method does not produce a file that is recognized by Import. However, one can write: Export["matrix2.h5.gz", datapourrie, {"GZIP", "HDF5"}] And then: d2 = Import["matrix2.h5.gz", {"Datasets", "/Dataset1"}]; datapourrie == d2 True


3

The Base64 string you provided as an example is not an encoding of a gzip stream (RFC 1952). It is an encoding of a zlib stream (RFC 1950). For background, those are different wrappers around the raw "deflate" compressed data format (RFC 1951), where the wrappers are headers and trailers proving information on the compressed data and integrity check ...


3

This is a quite handy approach of encoding Mathematica-expressions, even complete notebooks, as grayscaled images, which can be posted as PNG-files (and decoded afterwards). Code for encoding and decoding is as follows: (* general encoding to grayscale data *) seEncode[expr_] := Block[{cc = ToCharacterCode[Compress[expr]], olen, a}, olen = ...


3

One workaround is to compress the HDF5 file after it has been exported from Mathematica, using the HDF5 command line tools. Note: on OS X the command line tools can be easily installed using MacPorts using port install h5utils. The command to recompress the data is h5repack -v -f GZIP=1 infile.h5 outfile.h5 This can indeed achieve a significant ...


2

Create a matrix, and compress a column a = RandomInteger[10, {3, 3}] b = Transpose@{a[[1]], Compress /@ a[[2]], a[[3]]} Uncompress it: Quiet@Map[Check[Uncompress[#], #] &, a, {2}] Edit Instead of Quiet[] you could use Off[Uncompress::string] so other error messages are not hindered


1

It seems there is a undefined variable games in the compressed data. The code in the compressed data attempts to do a union on this games variable and some lists. So essentially, the error you get is the same one caused by Union[{}, games] To see it for yourself, try using Uncompress with two arguments. I suggest to use HoldComplete as a second argument. ...



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