Stream: helpdesk (published)

Topic: Converting .mat file to Julia matrix


view this post on Zulip Dale Black (Feb 09 2022 at 22:37):

I am using MAT.jl to load a .mat file. I am receiving strange errors saying that the .mat file contains a ; but I can't seem to find it. Does anyone have any idea how to solve this problem?

Here is how I loaded the matrix into julia:

vars = matread(path)
mat = vars["s100"]
mat = Int16.(round.(mat))

And this is the output I am getting:
image.png

view this post on Zulip Fredrik Ekre (Feb 09 2022 at 22:50):

What is the error message? You seem to have successfully loaded and converted the data to Int16s?

view this post on Zulip Fredrik Ekre (Feb 09 2022 at 22:51):

Maybe you should be looking for

julia> Int16(';')
59

view this post on Zulip Dale Black (Feb 09 2022 at 22:53):

I am surprised it shows that the matrix contains a ; I guess, but I might be looking in the wrong direction. The error message is a little later on after I use this matrix to convert it to a DICOM file using DICOM.jl. If it helps this is the error message when trying to write this matrix as a DICOM file and then load it again:

ArgumentError: cannot parse ";" as Float64

_parse_failure(::Type, ::SubString{String}, ::Int64, ::Int64)@parse.jl:373
#tryparse_internal#452@parse.jl:369[inlined]
tryparse_internal@parse.jl:367[inlined]
#parse#453@parse.jl:379[inlined]
parse@parse.jl:379[inlined]
(::DICOM.var"#18#21")(::SubString{String})@DICOM.jl:282
iterate@generator.jl:47[inlined]
_collect(::Vector{SubString{String}}, ::Base.Generator{Vector{SubString{String}}, DICOM.var"#18#21"}, ::Base.EltypeUnknown, ::Base.HasShape{1})@array.jl:744
collect_similar@array.jl:653[inlined]
map@abstractarray.jl:2849[inlined]
read_element(::IOStream, ::DICOM.DICOMData)@DICOM.jl:264
var"#read_body!#16"(::UInt16, ::typeof(DICOM.read_body!), ::IOStream, ::DICOM.DICOMData)@DICOM.jl:234
#dcm_parse#15@DICOM.jl:183[inlined]
var"#dcm_parse#14"(::Base.Pairs{Symbol, Dict{Tuple{UInt16, UInt16}, String}, Tuple{Symbol}, NamedTuple{(:aux_vr,), Tuple{Dict{Tuple{UInt16, UInt16}, String}}}}, ::typeof(DICOM.dcm_parse), ::String)@DICOM.jl:161
#10@none:0[inlined]
iterate@generator.jl:47[inlined]
collect(::Base.Generator{Vector{String}, DICOM.var"#10#12"{Base.Pairs{Symbol, Dict{Tuple{UInt16, UInt16}, String}, Tuple{Symbol}, NamedTuple{(:aux_vr,), Tuple{Dict{Tuple{UInt16, UInt16}, String}}}}}})@array.jl:724
#dcmdir_parse#9@DICOM.jl:149[inlined]
top-level scope@Local: 1[inlined]

Last updated: Nov 06 2024 at 04:40 UTC