Calling a functions fieldname without saying its name.

Hi there,
I have a structure called 'AerodynamicData.Cx.ActuatorName' where x is a wildcard character and ActuatorName is a wildcard phrase.
For example, I have structure called 'AerodynamicData'. This structure has two fields called Cm and Cp. Inside Cm there are two fields. Inside Cp there is one field.
AerodynamicData.Cm.BodyFlap
AerodynamicData.Cm.Speedbrake
AerodynamicData.Cp.Aileron
Possible structures^^
Now my question is how do I loop through all the structures that have this naming convention >> 'AerodynamicData.Cx.ActuatorName'

 Réponse acceptée

Mohammad Sami
Mohammad Sami le 1 Juin 2020
Modifié(e) : Mohammad Sami le 1 Juin 2020
You can use the function fieldnames and a for loop
%s = somestruct
f1 = fieldnames(s)
for i = 1:length(f1)
fn1 = f1{i};
s2 = s.(fn1);
f2 = fieldnames(s2)
for j = 1:length(f2)
fn2 = f2{j};
value = s2.(fn2);
% do something with the value
end
end

Plus de réponses (0)

Catégories

En savoir plus sur SimEvents dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by