4

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

1

1 Answer 1

5

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.