필터 지우기
필터 지우기

How to encode a matlab table in json

조회 수: 31 (최근 30일)
Chiara Labate
Chiara Labate 2017년 10월 30일
답변: Andrew Diamond 2021년 7월 18일
I have a table filled in matlab and now I would like to encode it in json format. How to do? I should show the headers of each columns and also their value. thanks you!! Chiara

답변 (2개)

JClarcq
JClarcq 2018년 3월 5일
just do
str=jsonencode(tab);
tab2=jsondecode(str);
Be careful: I noticed that if you use table properties VariableUnits, then it gets lost!!

Andrew Diamond
Andrew Diamond 2021년 7월 18일
From my experiments, jsonencoding a table, writing, then jsondecoding the file returns an equivalent array of structures. You can convert back to a table via struct2table but that assumes you knew it was a table to begin with.
So, I guess you would have to do it "manually" by changing each table to output into, say, a structure with a table field and a unique ID field so that after this structure (with the ID and table field) was read back in, you could parse the returned item for such structures and just, now with foreknowledge, convert the table field back to a table via struct2table.
Not very pretty

카테고리

Help CenterFile Exchange에서 JSON Format에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by