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

1 次查看(过去 30 天)
masahiro yasuda
masahiro yasuda 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 CenterFile Exchange 中查找有关 データ型の変換 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!