2016-09-01 88 views
-2

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

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 

如何解决这个问题?

谢谢

回答

4

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

另请先仔细阅读文档:

例如, 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