您可以使用DelimitedFiles
stdlib中的模块:
julia> using DelimitedFiles
julia> s = """
1,2,3
4,5,6
7,8,9"""
"1,2,3\n4,5,6\n7,8,9"
julia> b = IOBuffer(s)
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=17, maxsize=Inf, ptr=1, mark=-1)
julia> readdlm(b, ',', Float64)
3×3 Array{Float64,2}:
1.0 2.0 3.0
4.0 5.0 6.0
7.0 8.0 9.0
Run Code Online (Sandbox Code Playgroud)
我向您展示的示例读取IOBuffer
是完全可重复的,但是您也可以从文件读取数据。在文档字符串中,readdlm
您可以找到有关可用选项的更多详细信息。
请注意,您将获得 Matrix{Float64}
不Vector{Float64}
,但我知道这是你想要的。如果不是,则为了将矩阵转换为向量,可以vec
在读取数据后在其上调用函数。