MATLAB Answers

How to convert cell to a struct with fields and multiple dimensions?

2 ビュー (過去 30 日間)
Maria Hart
Maria Hart 2021 年 1 月 21 日
コメント済み: Maria Hart 2021 年 1 月 22 日
Dear all,
I have a cell (P_ungedeckt_h) with multiple dimensions:
P_ungedeckt_h is a 2x1 matrix each containing a struct:
This struct is in turn is devided in fields containing a 8760x1 vector:
I would now like to create from this a variable which is called P_ungedeckt and contains P_ungedeckt.el which is a vector 17520x1 with all .el values below eacht other and a P_ungedeckt.th with the same.
I got this so far,
P_ungedeckt = cell2mat(P_ungedeckt_h);
however it is not quite what I want as it gives me this:
But my goal is not to have the two rows each containing a 8760x1 double. I wish to have 17520 ( = 2x8760) rows, so first the 8760 values of the first double and then the next 8760 beneath that.
I hope this is understandable.
With kind regards
Maria
  2 件のコメント
Image Analyst
Image Analyst 2021 年 1 月 21 日
Yvan, this looks like an Answer to me, so it should be an official "Answer" down below rather than up here in the comments section which is used to ask the poster for clarification or to attach missing files or code. You can even get "credit" if you post it in the Answers section.

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

採用された回答

Jon
Jon 2021 年 1 月 21 日
編集済み: Jon 2021 年 1 月 21 日
I think this would do what you are looking for
% example make up some data just to try it
P_ungedeckt_h = cell(2,1);
for k = 1:2
P_ungedeckt_h{k,1}.th = rand(8760,1);
P_ungedeckt_h{k,1}.el = rand(8760,1);
end
% make the desired structure
P_ungedeckt.el = [P_ungedeckt_h{1,1}.el;P_ungedeckt_h{2,1}.el];
P_ungedeckt.th = [P_ungedeckt_h{1,1}.th;P_ungedeckt_h{2,1}.th];
  3 件のコメント
Maria Hart
Maria Hart 2021 年 1 月 22 日
Thank you very much!

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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by