Access the data from a Struct

1 view (last 30 days)
Susan
Susan on 30 Mar 2020
Commented: Susan on 31 Mar 2020
I have a struct with fields
val = struct with fields:
abstract: [1×1 struct]
body_text: [72×1 struct]
when I extract the text data in body_text using "val.body_text.text" I got 72*1 struct. But when I try "A = val.abstract.text", I got only the first struct of the 72 structs. How can I put all these [72×1 struct] into A?
Thanks!
  3 Comments
Susan
Susan on 30 Mar 2020
Sorry for the confusion! What I meant was "But when I try "A = val.body_text.text", I got only the first struct of the 72 structs"

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 30 Mar 2020
Edited: Ameer Hamza on 30 Mar 2020
Try this, if the data in the field 'text' is scalar
A = [val.abstract.text];
If it is vector than try
A = {val.abstract.text};
  5 Comments
Susan
Susan on 31 Mar 2020
Thank you so much! I really appreciate your help.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!