2

I need to export my data into a .txt document to import it in $\LaTeX$. For a given M, I used the follow code to export:

data =
  Cases[
    Plot[M[n1, d1, n2, d2, nb],
     {alpha, 0, 2 Pi},
     PlotPoints -> 3000, MaxRecursion -> 0],
    Line[data_] :> data, -4, 1][[1]];
    Export["M_AB.txt", data, "Table"]

The problem is that the whole range is not exported. The range of the .txt file is from 0 to 1.566 (1.5708 would be $\pi/2$). Then i tried to set the range manually by using {0, 2 Pi}, {Pi/2, 2 Pi}, {3/2 Pi, 2 Pi}. Then I had gaps in the plots. Here is a picture how it looks like in Mathematica (left) and how it looks in $\LaTeX$ with the gaps, after adding it manually (right). enter image description here

Why doesn't Mathematica export the whole range?

Pillsy
  • 18,498
  • 2
  • 46
  • 92
  • Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs!
    3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
    –  Oct 26 '15 at 13:56
  • Possible duplicate of http://mathematica.stackexchange.com/questions/19859/plot-extract-data-to-a-file – Pillsy Oct 26 '15 at 14:04
  • Looking again at the previous answer, it looks like it doesn't address this specific question. However, it would help if you provided us with the definition of M so we can investigate in more detail. – Pillsy Oct 26 '15 at 14:31
  • 2
    We need the definition of M. If you try substituting an arbitrary built in function (e.g. Sin[alpha]) in your export routine, does that work? I tried that on my side and I did get a list of 3000 points as expected. Was the MMA plot you show generated using the exact same parameters as the one in the Cases expression? I am worried that disabling the adaptive routines (MaxRecursion -> 0) might make Plot partially miss the peaks in your function. – MarcoB Oct 26 '15 at 14:55
  • 2
    Since you are setting MaxRecursion -> 0 anyway (which prevents Plot from doing adaptive sampling), why are you generating the function values in such a complicated, roundabout manner? Why don't you just use Table[{x, f[x]}, {x,...}] instead? – Szabolcs Oct 26 '15 at 14:57
  • Also, are you certain that not all of the data is exported? Could it be that the other plotting software is downsampling it because it doesn't like as many as 3000 points? – Szabolcs Oct 26 '15 at 15:00
  • @Szabolcs. The OP might be extracting points from the plot in an attempt to take advantage of adaptive sampling to get a better representation of the narrow spikes in the data. – m_goldberg Oct 26 '15 at 15:24
  • @m_goldberg That's what I assumed, but then I noticed that he turned off adaptive sampling with MaxRecursion -> 0. – Szabolcs Oct 26 '15 at 15:27

0 Answers0