Help with the getfield command?

1 回表示 (過去 30 日間)
Kevin Bachovchin
Kevin Bachovchin 2013 年 3 月 21 日
Hello,
I have a struct S and I'm trying to access the values of each field without having to hard code in the field names.
The code getfield(S,'x1') works. 'x1' is one of the fields of S.
However the following code, when I do not hard code in the field name, does not work
MyFieldNames = fieldnames(S);
getfield(S,MyFieldNames(1));
I need to be able to iterate through the field names without hard coding the names. Is there someone way to do that?
Thank you, Kevin

採用された回答

Kevin Bachovchin
Kevin Bachovchin 2013 年 3 月 21 日
Oh, I need to use getfield(S,MyFieldNames{1});

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by