Searching data inside struct fields ?

조회 수: 6 (최근 30일)
Mohammed kandeel
Mohammed kandeel 2018년 1월 20일
댓글: Mohammed kandeel 2018년 1월 20일
I have struct and i need i need to search inside it how can i make this ? let's say i have struct contains fields ID, name and class i need when i get ID from user not accept it if it's found before.
Thanks In advance.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 1월 20일
if ismember(proposed_id, {structname.ID})
It was a duplicate
else
It did not occur before
end
If the ID are numeric change from {} to []
  댓글 수: 4
Stephen23
Stephen23 2018년 1월 20일
편집: Stephen23 2018년 1월 20일
This code
class.ID=1;
class.ID=2;
class.ID=3;
simply overwrites the field ID with each line, and so defines just one single scalar structure with one field. It is equivalent to:
class.ID=3;
What are you actually trying to achieve? You might need to read about non-scalar structures:
Mohammed kandeel
Mohammed kandeel 2018년 1월 20일
It's working my Bro its should be like this it's my fault.
class(1).ID=1;
class(2).ID=2;
class(3).ID=3;

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

카테고리

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