Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BitVectors of length 1 are saved as scalars not arrays #163

Open
bjarthur opened this issue Jul 28, 2021 · 1 comment
Open

BitVectors of length 1 are saved as scalars not arrays #163

bjarthur opened this issue Jul 28, 2021 · 1 comment

Comments

@bjarthur
Copy link
Member

julia> using MAT

julia> matwrite("foo.mat", Dict("x"=>trues(1)))

julia> matread("foo.mat")
Dict{String, Any} with 1 entry:
  "x" => true

julia> matwrite("foo.mat", Dict("x"=>trues(2)))

julia> matread("foo.mat")
Dict{String, Any} with 1 entry:
  "x" => Bool[1, 1]

the workaround:

julia> matwrite("foo.mat", Dict("x"=>convert(Array{Any}, trues(1))))

julia> matread("foo.mat")
Dict{String, Any} with 1 entry:
  "x" => Any[true]
@inkydragon
Copy link

The behavior of the existing API is correct.

Generating test mat file in julia:

matwrite("ju.mat", 
    Dict(
        "x1"=>trues(1),
        "x2"=>trues(2),
        "x3"=>convert(Array{Any}, trues(1))     
))

Read the test mat file in MATLAB:

>> clear
>> load('ju.mat')
>> x1
x1 =

  logical

   1

>> x2
x2 =

  2×1 logical array

   1
   1

>> x3
x3 =

  1×1 cell array

    {[1]}

Write mat file in MATLAB:

>> clear
>> m1 = logical([1])
m1 =

  logical

   1

>> m2 = logical([1; 1])
m2 =

  2×1 logical array

   1
   1

>> m3 = logical([1 1])
m3 =

  1×2 logical array

   1   1

>> m4 = {1}
m4 =

  1×1 cell array

    {[1]}

>> m5 = {logical(1)}
m5 =

  1×1 cell array

    {[1]}

>> save('m.mat')

Read mat file in julia:

julia> matread("m.mat")
Dict{String, Any} with 5 entries:
  "m3" => Bool[1 1]
  "m2" => Bool[1; 1]
  "m4" => Any[1.0]
  "m5" => Any[true]
  "m1" => true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants