JuliaIO / MAT.jl

Julia module for reading MATLAB files
MIT License
278 stars 71 forks source link

write 1-length Float64[] results in scalar #51

Closed bjarthur closed 8 years ago

bjarthur commented 8 years ago

is this by design? a 1-length Any[] results in a vector, but a 1-length Float64[] results in a scalar:

julia> fid=matopen("foo.mat","w")
MAT.MAT_HDF5.MatlabHDF5File(HDF5 data file: foo.mat,true,true,0)

julia> write(fid,"any",Any[7.])

julia> write(fid,"float64",Float64[7.])

julia> close(fid)

julia> d=matread("foo.mat")
Dict{ByteString,Any} with 2 entries:
  "any"     => Any[7.0]
  "float64" => 7.0

julia> typeof(d["any"])
Array{Any,1}

julia> typeof(d["float64"])
Float64

julia> typeof(Any[7.])
Array{Any,1}

julia> typeof(Float64[7.])
Array{Float64,1}
simonster commented 8 years ago

Because MATLAB does not differentiate between scalars and one-element numeric matrices, one of the two can't round-trip. The current behavior is probably more convenient, but perhaps not entirely consistent. 1-element Vector{Any} corresponds to a MATLAB cell array which has different semantics in MATLAB.

bjarthur commented 8 years ago

makes sense. thanks.