Retrieve a list of simscape.logging.Node names from simlog or other inner nodes

4 vues (au cours des 30 derniers jours)
CCC
CCC le 16 Juin 2021
Commenté : CCC le 22 Juin 2021
How do you retrieve as a cell, strings or other indexable array a list of nodes in the simlog?
example:
ssc_dcmotor
sim('ssc_dcmotor');
that returns
simlog_ssc_dcmotor
I want an array:
list(1) = 'ERef';
list(2) = 'DC_Motor'
list(3) = 'DC_Voltage';
etc.
From there I could call or similar.
eval('simlog_ssc_dcmotor.list(2)')
The same with 'DC_Motor' (which would be list(2))
how do I generate a list of its simscape.logging.Nodes of 'DC_Motor'?
MATLAB comes with print(simlog_ssc_dcmotor.) but you cannot store it like:
a = print(simlog_ssc_dcmotor);

Réponse acceptée

Yifeng Tang
Yifeng Tang le 18 Juin 2021
fieldnames(simlog_ssc_dcmotor) seems to work OK for me. Same way you would get the names of a structure variable.
ssc_dcmotor
sim('ssc_dcmotor');
list = fieldnames(simlog_ssc_dcmotor);
% list =
%
% 10×1 cell array
%
% {'id' }
% {'savable' }
% {'exportable' }
% {'ERef' }
% {'Sensing' }
% {'Load_Torque' }
% {'DC_Voltage' }
% {'DC_Motor' }
% {'MRRef_Motor' }
% {'MRRef_Torque'}
Just ignore the first three.
  1 commentaire
CCC
CCC le 22 Juin 2021
It worked like a charm with eval to create the lists of sub components and retrieve values().
I find rather strange to use that method if you don't know the names of the components a prori.
Thank you very much.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Equations dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by