How to use a struct array field as input in function

3 Ansichten (letzte 30 Tage)
Jerome Lafrance
Jerome Lafrance am 7 Feb. 2016
Kommentiert: Jerome Lafrance am 7 Feb. 2016
Hi! I'm sorry if this question have already been asked, but I can't figure how to do this.
So here's what I'm trying to do :
I have a struct array with 4 fields inside it
LittlePoney.Blue;
LittlePoney.Purple;
LittlePoney.Green;
LittlePoney.Red;
I would like to create a function which use the field as an input. Like This :
function [A] = BigBrother(Field)
LittlePoney.Field;
end
If someone can help me with this I'd be really happy.
Waiting for your answers Thank you

Akzeptierte Antwort

Jan
Jan am 7 Feb. 2016
Bearbeitet: Jan am 7 Feb. 2016
Look for the term "dynamic field names":
LittlePoney.Blue = 1;
LittlePoney.Purple = 2;
LittlePoney.Green = 3;
LittlePoney.Red = 4;
Field = 'Green';
LittlePony.(Field)

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by