table2stru​ct関数の挙動に疑問​があります.「構造体​→テーブル→構造体」​の順でデータを変換し​ても元に戻らないのは​おかしいのではないで​しょうか?

7 ビュー (過去 30 日間)
masahiro yasuda
masahiro yasuda 2022 年 12 月 5 日
コメント済み: Atsushi Ueno 2022 年 12 月 5 日
s = struct('a',{1,2},'b',{3,4})
st = struct2table(s)
sts = table2struct(st)
上のコードを実行した場合,構造体sは1x2 structですが,復元した構造体stsは2x1 structになります.
s(2)とsts(2)は同じ値を示しますが,sとstsでサイズが異なるというのは違和感があります.sts'のように転置をすれば解決しますが,table2struct関数の出力サイズを1xNにするべきではないでしょうか?
  1 件のコメント
Atsushi Ueno
Atsushi Ueno 2022 年 12 月 5 日
1xNの行ベクトルにすると元に戻ります。しかしこれは求めている table の形でしょうか?
s = struct('a',[1,2,3,4],'b',[5,6,7]);
st = struct2table(s)
st = 1×2 table
a b ________________ ___________ 1 2 3 4 5 6 7
sts = table2struct(st)
sts = struct with fields:
a: [1 2 3 4] b: [5 6 7]

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File Exchangeデータ型の変換 についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!