2016-09-01 89 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