Searching data inside struct fields ?
3 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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
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:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!