Access Field from Struct

조회 수: 128 (최근 30일)
N/A
N/A 2020년 9월 25일
편집: Stephen23 2020년 9월 25일
Hello everyone,
I need your help with accessing a field from a struct. I am not really familiar with how to use structs.
I got this struct (not mine, therefore I don't really know how to properly work with it) and just want to plot the values that are in the first column.
There is probably a really easy way how to do it. I tried to access the data with something like a=structname.MeansArea, but this gives me only the very first entry of the column. I apprechiate all help.
  댓글 수: 1
Stephen23
Stephen23 2020년 9월 25일
편집: Stephen23 2020년 9월 25일
Structure arrays have two independent features which need to be considered when accessing their data:
  • the size, which determines what indexing you can use.
  • the fields, which determines what field names you can use.
For non-scalar structures you will likely find comma-separated lists to be very useful:
It is also possible to access the fieldnames dynamically:

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 9월 25일
편집: Ameer Hamza 2020년 9월 25일
You need to use concatenation brackets [ ]
a=[structname.MeansArea]
  댓글 수: 2
N/A
N/A 2020년 9월 25일
Thanks for the fast and correct answer.
Ameer Hamza
Ameer Hamza 2020년 9월 25일
I am glad to be of help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by