Conversion from string to matrix

You can also just use comma-delimited text, e.g. via the DelimitedFiles library or several other libraries:

julia> using DelimitedFiles

julia> writedlm("cpx.csv", [1.0 + 1.0im 1.0 + 0.0im; 5.0 + 0.0im 0.0 + 0.0im], ',')

julia> readdlm("cpx.csv", ',', ComplexF64)
2×2 Matrix{ComplexF64}:
 1.0+1.0im  1.0+0.0im
 5.0+0.0im  0.0+0.0im

These have the advantage of being more human-readable and more portable across Julia versions.

See also the discussion thread: Saving an array of complex numbers

5 Likes