# Multiplot, extract data to a file

I used NDSolve to solve a system of ODE, and the resulting n functions y1[x], y2[x],... yn[x] were plotted with the Plot command, as follows,

Plot[{y1[x], y2[x],... yn[x]}/.%,{x,min,max}]


So I need to export the data in .txt multicolumn format. The answer to question  provided me a clue,

data = Cases[Plot[Sin@x, {x, 0, 2 Pi}], Line[data_] :> data, -4, 1][]


however, I need the appropriate pattern/specification/etc for Cases. Or, alternatively, is there another way to export data?

Thank you

• Please include the complete code, including the part that generates the answer you are substituting into plot, or alternatively generate a minimal working example with fake data that still represents the structure of your problem. What you have may not be enough detail for us to help meaningfully. Nov 3, 2021 at 12:34
• What should "/.%" mean? Nov 3, 2021 at 13:00
• Hi @celsodad Welcome to MmaSE, there is so much to learn when one starts here. Please start by taking the tour now. It will help us to help you if you write an excellent question. Always edit your question if improvable, show due diligence, give brief context, include minimal working example of code and data in formatted form. As you receive help, we hope you will give back too by voting and answering questions. Please keep the site useful, be kind, correct mistakes and share what you have learned. Nov 3, 2021 at 13:03
• I think this question needs clarification. What is the motivation? Why extract data from a plot instead of using the data that created the plot on the first instance? What is the actual code used? This reduced version is not a minimum working example. The OP should show minimum due diligence, as the limited information provided requires speculation from anybody trying to offer an answer. Nov 3, 2021 at 13:05
• "Or another way to export data to .txt": Try data = RandomReal[{-4, 4}, 20] and then: Export["C:\\data.txt", data] .
– Syed
Nov 3, 2021 at 13:28

Let's say you solve the following equation:

sol = DSolve[x^2*y''[x] + 5*x*y'[x] + 6*y[x] == 0, y[x], x]

{{y[x] -> (C Cos[Sqrt Log[x]])/x^2 + (C Sin[Sqrt Log[x]])/
x^2}}


Create a table: modify the range and increments as required.

dexp = Table[{x, y[x] /. sol[]}, {x, 0.1, 0.5, 0.05}] /. {C ->
1, C -> 2}


Try both formats:

Export["C:\\dexp_1_2.txt", dexp]
Export["C:\\dexp_1_2.csv", dexp, "CSV"]


You can extend the Table above, by adding more entries according to your solution.

Thanks a lot. I succesfully adapted the above suggestion for n equations :

sol = NDSolve[{Table[y[i]''[x] + y[i][x], {j, 1, n} == 0, {i, 1, 100}], Table[y[i] == i, {i, 1, n}], Table[y[i]' == 0, {i, 1, n}]}, {y, y, ... y[n]}, {x, 0, 15}]

dexp = Table[{t, y[x], y[x], ... y[n][x]} /. sol[], {x, 0, 15, .01}]

Export["C:\...\dexp_1_2.txt", sol]


(I used NDSolve to account for more complex ODEs)