I have used Matlab and now try to convert some code to Julia.
% Load data in Matlab
fileID = fopen('./data_6000x3199.bin');
Data = fread(fileID,[6000,3199],'single');
fclose(fildID);
However, I have no idea how to read this single type binary file in Julia code. Can someone help this, please?
read!
will fill an array with data read from a binary file:
julia> x # original array
2×2 Array{Float32,2}:
1.0 3.0
2.0 4.0
julia> write("test.bin", x) # write to binary file
16
julia> y = Array{Float32}(undef, 2, 2); # create a container for reading data
julia> read!("test.bin", y) # read data
2×2 Array{Float32,2}:
1.0 3.0
2.0 4.0
'single'
means single precision floating point, which is represented with Float32
in Julia. Your example MATLAB code will translate to this Julia code:
data = Array{Float32}(undef, 6000, 3199)
read!("data_6000x3199.bin", data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With