How to use a struct array field as input in function

3 次查看(过去 30 天)
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

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by