De-serialze char array to object
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I'm trying to convert a char array to an object. The char array used to be a MATLAB object which has been serialized and has a structure like this:
hBeams.stackUseStartPower = 1
hBeams.stackUserOverrideLz = false
hChannels.channelAdcResolution = {12 12 12 12}
hChannels.channelDisplay = [1;2;3;4]
(This is just a small portion of the char, there is much more data in reality).
Basically, I wat to de-serialze the string and recover the object so I can access its values.
When I use eval() it parses the string into an object and stores it in the current workspace. However, I need to store the data in a variable of another object.
Also, since it is usually not recommended to use eval(), is there a better (more elegant) way to do this?
Best,
Gebhard
댓글 수: 0
답변 (1개)
Stephen23
2018년 11월 22일
"is there a better (more elegant) way to do this?"
save and load, or:
댓글 수: 5
Guillaume
2018년 11월 22일
so I guess there are not many options how to store that data
There are plenty of well established techniques for storing metadata. In TIFF files, they could have used private tags (and documented them). Alternatively, they could have used common serialisation formats instead of inventing their own. The two most common serialisation formats, json and xml, are both supported by matlab and can be transformed into a single variable in one line:
settings = jsondecode(serialisedstream);
참고 항목
카테고리
Help Center 및 File Exchange에서 JSON Format에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!