How to use a struct array field as input in function

조회 수: 3 (최근 30일)
Jerome Lafrance
Jerome Lafrance 2016년 2월 7일
댓글: Jerome Lafrance 2016년 2월 7일
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