Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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);

Akzeptierte Antwort

Yifeng Tang
Yifeng Tang am 18 Jun. 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 Kommentar
CCC
CCC am 22 Jun. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Equations finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by