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

1 view (last 30 days)
Maria Hart on 21 Jan 2021
Commented: Maria Hart on 22 Jan 2021
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 CommentsShowHide 1 older comment
Image Analyst on 21 Jan 2021
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 on 21 Jan 2021
Edited: Jon on 21 Jan 2021
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];
Maria Hart on 22 Jan 2021
Thank you very much!