How do I look up a string in a struct and assign the number value that is associated with the string

1 view (last 30 days)
I have a struct where I specify strings that indicate certain quality levels for validation:
VAL.qualityTypes = struct('POOR', 1, 'FAIR', 2, 'GOOD', 3);
I have another variable ('quality') that contains one of these strings in a cell.
quality = 'GOOD'
What code would I use to obtain the number associated with the specific string, like so:
qualityNumber = 3

Accepted Answer

Matt J
Matt J on 14 Sep 2018
qualityNumber = VAL.qualityTypes.(quality)

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!