Saving output to txt/CSV file?

Hi guys, I am dealing with output saving, I have tried several ways referred to docs. But nothing works for me.
The output I want to save look like this

julia> sim_result
GpABC.SimulatedABCRejectionOutput(3, 1465, 20000, 1.0, [4.5398045285832636 16.341298256602684 0.8528241692701137; 2.2014098882111117 11.88704704892733 1.8060482719350048; … ; 3.4569125171576727 14.206295598447817 1.2527525901911478; 1.1086538611233734 16.95205292134931 0.7814523160265465], [0.8718784407104312, 0.9897439825224637, 0.7361435718656393, 0.7863129137954922, 0.8097276891293583, 0.7167559341428585, 0.6600858843737456, 0.7420732257406872, 0.8085779131629843, 0.7603566788770011  …  0.9172504543539195, 0.5578993725435081, 0.8377191750525664, 0.7847440234430122, 0.6465487321194205, 0.716785821691151, 0.2596989086130145, 0.7210284576525666, 0.9855259563757373, 0.5775313512469311], [0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899  …  0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899, 0.0006825938566552899])

And its structure is
GpABC.SimulatedABCRejectionOutput(::Int64, ::Int64, ::Int64, ::Float64, ::AbstractArray{Float64,2}, ::AbstractArray{Float64,1}, ::StatsBase.Weights)
I want to save the ::AbstractArray{Float64,2} to a TXT or CSV file.

You’ll need to find out how the array is stored in your sim_result object by doing fieldnames(typeof(sim_result)). Let’s assume the field is called data, you can then either do using DelimitedFiles; writedlm("output.txt", sim_result.data) to write a simple delimited text file, or using CSV; CSV.write("output.csv", (data = sim_result.data, )) (note the comma which creates a NamedTuple) to write a csv.

That works! Thanks a lot!

julia> fieldnames(typeof(sim_result))
(:n_params, :n_accepted, :n_tries, :threshold, :population, :distances, :weights)

julia> DelimitedFiles; writedlm("output.txt", sim_result.:population)

julia>
1 Like