How to work with Struct With Struct construction
5 views (last 30 days)
Show older comments
Hello.
I converted json.data to string and converted string to struct using jsondecode. Got the next struct like:
data =
struct with fields:
A1: [1×1 struct]
A2: [1×1 struct]
A3: [1×1 struct]
A4: [1×1 struct]
A5: [1×1 struct]
A6: [1×1 struct]
How to work with this construction, I mean let's say i need data from A1: [1x1 struct] (this structure contains the name of the variables and its value). How can I get it?
And can I convert this construction to massive with A1 ... A2 - rows and data from [1x1 struct] - columns?
0 Comments
Accepted Answer
Jan
on 16 Dec 2021
It is not clear, how the inputs data exactly look and what you want as output. Prefer to post some code, which produces both.
Maybe you want:
C = struct2cell(data);
Result = cat(1, C{:});
5 Comments
More Answers (1)
Walter Roberson
on 16 Dec 2021
names = structfun(@(S) S.Name, Data);
values = structfun(@(S) S.Value, Data, 'uniform', 0);
catval = cell2mat(values(:).')
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!