Vector dimesions are different before encoding json and after decoding json

21 ビュー (過去 30 日間)
CHV
CHV 2022 年 3 月 3 日
コメント済み: CHV 2022 年 3 月 9 日
Before encoding to json file the mat files are having vectors are as row vector. But after encoding (jsonencode) and decoding(jsondecode), the vectors are changed to column vectors in workspace. And I want the same dimensions after decoding also, how can I get that ?
b.c = 22;
a= jsonencode(b);
d=jsondecode(a);
  2 件のコメント
CHV
CHV 2022 年 3 月 3 日
編集済み: CHV 2022 年 3 月 3 日
Transpose is easy for few variables and above one I have shown is just one variable.But I am having lot of variables with different dimensions as structure array.After decoding I need same dimensions as before encoding.

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

採用された回答

Ive J
Ive J 2022 年 3 月 3 日
編集済み: Ive J 2022 年 3 月 3 日
How about this?
mystr.f1 = 1:4;
mystr.f2 = (1:4).';
js = jsonencode(mystr);
newstr = jsondecode(js)
newstr = struct with fields:
f1: [4×1 double] f2: [4×1 double]
fnames = fieldnames(mystr);
fnames = fnames(structfun(@isrow, mystr)); % field names to be changed
for i = 1:numel(fnames)
newstr.(fnames{i}) = newstr.(fnames{i}).';
end
newstr
newstr = struct with fields:
f1: [1 2 3 4] f2: [4×1 double]
  3 件のコメント
CHV
CHV 2022 年 3 月 9 日
Thanks for the explanation and its worked.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeJSON Format についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by