How to use a struct array field as input in function

3 visualizaciones (últimos 30 días)
Jerome Lafrance
Jerome Lafrance el 7 de Feb. de 2016
Comentada: Jerome Lafrance el 7 de Feb. de 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

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by