Find index in struct field in which word appears
18 views (last 30 days)
Show older comments
I have a 1×1 cell array - SubjectName = {'Subject3'}. How do I find the row in which this appears in the attached struct in which the subjects are listed in the field 'Subject'?
0 Comments
Answers (1)
Stephen23
on 9 Nov 2021
Edited: Stephen23
on 9 Nov 2021
"How do I find the row in which this appears in the attached struct in which the subjects are listed in the field 'Subject'?"
Your structure has size 1x3, so it actually has one row and three columns.
S = load('SampleStruct.mat').SampleStruct
SubjectName = {'Subject3'};
idx = strcmp([S.Subject],SubjectName) % logical index
ndx = find(idx) % linear index
Why are you storing all of the character vectors in scalar cells? There does not seem to be any point in that.
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!