How to use a struct array field as input in function

1 view (last 30 days)
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

Accepted Answer

Jan
Jan on 7 Feb 2016
Edited: Jan on 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)

More Answers (0)

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!