Access the data from a Struct
이전 댓글 표시
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
dpb
2020년 3월 30일
"when I try "A = val.abstract.text"
But
val = struct with fields:
abstract: [1×1 struct]
body_text: [72×1 struct]
so val.abstract.text is either invalid reference or is the name of the 1x1 struct under val.abstract
The array of 72 stuct is contained in the val struct field .body_text
It isn't clear why you think there should be more than one element from the reference above...of course, we can't see what the content of these embedded struct is so we've no idea what are fieldnames thereof.
Seems like a very convoluted nested storage--my first recommendation would be to see if you can't somehow simplify this drastically.
Ameer Hamza
2020년 3월 30일
''so val.abstract.text is either invalid reference or is the name of the 1x1 struct under val.abstract'''
Not necessarily. For example
>> s.text = '123';
s.xyz = 2;
val.abstract = s;
val.body_text = repmat(s, 1, 72);
>> val
val =
struct with fields:
abstract: [1×1 struct]
body_text: [1×72 struct]
>> val.abstract.text
ans =
'123'
Susan
2020년 3월 30일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Web Services에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!