【问题标题】:Read files in a loop [julia]?循环读取文件 [julia]?
【发布时间】:2017-01-09 07:39:24
【问题描述】:

我成功地将文件存储在一个循环中。现在我有 1000 个文件,从 1 到 1000,我想读取它们但它不起作用。

for i in 1:1000
    h5open("path to file /file$i.h5", "w") do file
        write(file, "a", x)  # alternatively, say "@write file a"
    end
end

写作效果很好。但是当谈到阅读它们时它不起作用。

for i in 1:1000
    h5open("  path to files/file$i.h5", "w") do file
        read(file, "a", x)  # alternatively, say "@write file a"
    end
end

如何解决?

谢谢

【问题讨论】:

    标签: file makefile julia hdf5


    【解决方案1】:

    如果您遇到错误,您应该在问题中写下。

    另外请先仔细查看文档:

    例如https://github.com/JuliaIO/HDF5.jl https://github.com/JuliaIO/HDF5.jl/blob/master/doc/hdf5.md

    这里

    https://github.com/JuliaIO/HDF5.jl/blob/master/doc/hdf5.md

    要从文件read() 中读取,将采用两个参数,如本示例中的自述文件页面。还将读取的对象分配给变量 c。

    c = h5open("mydata.h5", "r") do file
        read(file, "A")
    end
    

    要将其放入 for 循环并读取其中的每个变量,最好构造一个数组或其他结构以将值放在首位。然后将 c 的索引分配给该变量,例如

    # initialise c to be 1000 elements X whatever you are reading in then ...
    for i in 1:1000
        c[i] = h5open("mydataFilenumber$i.h5", "r") do file
            read(file, "A")
        end
    end
    

    【讨论】:

      猜你喜欢
      • 2012-03-16
      • 1970-01-01
      • 2021-04-16
      • 1970-01-01
      • 2013-11-22
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 2012-03-27
      相关资源
      最近更新 更多