Searching data inside struct fields ?

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.

Réponses (1)

Walter Roberson
Walter Roberson le 20 Jan 2018
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 commentaires

Mohammed kandeel
Mohammed kandeel le 20 Jan 2018
It's not working my friend.
lets say i have the following
class.ID=1; class.ID=2; class.ID=3;
and i want to input new ID but user put 2 so i it's not accepted to entered the same ID how can i make it ?
Mohammed kandeel
Mohammed kandeel le 20 Jan 2018
Sorry it's working my friend.
Thanks
Stephen23
Stephen23 le 20 Jan 2018
Modifié(e) : Stephen23 le 20 Jan 2018
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:
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;

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by