フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to convert 182*1 struct with 20 fields to 1*1 struct with 20 fields?

1 回表示 (過去 30 日間)
Parthiban C
Parthiban C 2018 年 12 月 11 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have 20*182 cell which I need to convert to struct. By using cell2struct command I am getting 182*1 struct but I want 1*1 struct.
Source data fileCapture.PNG
  5 件のコメント
per isakson
per isakson 2018 年 12 月 11 日
編集済み: per isakson 2018 年 12 月 11 日
Are 'ParamXX' or 'NameYY' supposed to be used as field names ?
Parthiban C
Parthiban C 2018 年 12 月 11 日
column 1 is for field names

回答 (1 件)

Guillaume
Guillaume 2018 年 12 月 11 日
"This one is very close to what I need. In final answer I need 182*1 double instead of 1*182 double"
Well that's trivially fixed with your existing code by transposing your vector, so by replacing:
S.(data{jj}) = [data{jj,2:end}];
by
S.(data{jj}) = [data{jj,2:end}]';
Or you could do this:
%demo data: %Not sure why we bother about the first row since it's unused
data = [{'Description'}, compose('Name%02d', 1:182);
compose('Parm%02d', (1:20)'), num2cell(rand(20, 182))]
%conversion to structure
newdata = num2cell(cell2mat(data(2:end, 2:end))', 1);
S = cell2struct(newdata, data(2:end, 1), 2)

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by