I am new to Julia. I have been using MATLAB for quite a while. I have few matlab matices namely, A.mat, B.mat, C.mat and so on. I have to read these matrices into Julia and then do some optimization using them. I dont know how to convert these matlab matrices to Julia matrices. I have used the pkg MAT.jl. when I use use it as: A = matopen("A.mat") in julia then "A" is not a matrix in julia. How do I read convert these matrices to julia matrices. Any help will be appreciated. Thanks
You need to use the read
function
For this examples I will use the array.mat
that comes in MAT.jl
test suite.
julia> using MAT
julia> ff = matopen(joinpath(pathof(MAT),"../..", "test/v7/array.mat"));
julia> read(ff,"a2x2")
2×2 Matrix{Float64}:
1.0 3.0
4.0 2.0
If you want to define it as a variable in your namespace you can used assignment or the @read
macro:
julia> @read ff a2x2;
julia> a2x2
2×2 Matrix{Float64}:
1.0 3.0
4.0 2.0
Last but not least you might want to see the list of variables in your mat file:
julia> keys(read(ff))
KeySet for a Dict{String, Any} with 6 entries. Keys:
"empty"
"string"
"a2x1"
"a2x2x2"
"a2x2"
"a1x2"
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