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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by