How to find number of objects in a structure?

조회 수: 9 (최근 30일)
Ayesha ch
Ayesha ch 2016년 6월 19일
댓글: Ayesha ch 2016년 6월 20일
Hi I'm new to Matlab. I have the following struct array and I want to save the number of objects of struct in a variable. How can I find number of objects? Any help would be appreciated
  댓글 수: 1
Adam
Adam 2016년 6월 19일
편집: Adam 2016년 6월 19일
What do you mean by 'object'? You mean the number of fields or the total number of things across every field? In your example you seem to just mean the number of elements in one field of the struct. If that is the case then you would be better always calculating it on demand to ensure you don't have to keep it up to date. Even better, use a class and a dependent property, but that s slightly more advanced.

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

채택된 답변

Muhammad Usman Saleem
Muhammad Usman Saleem 2016년 6월 19일
Let i am creating a structure s below
S = struct('a', 0, 'b', 1, 'c', 2);
Now when i am investigating what is inside of struture i type
>> S
S =
a: 0
b: 1
c: 2
Now i want to access value of its first feild(which is a)
S.a
ans =
0
for value of last feild, type this
S.c
ans =
2
now let's say i want to modify value( new value of 10) of last feild(c) of strutre S , do this
S.c=10
S =
a: 0
b: 1
c: 10
if you want to delete any field of struture S , use this
S.a=[]
S =
a: []
b: 1
c: 10
Tell me if you need to learn more about struture?
Usman

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by