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

4 次查看(过去 30 天)
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);

采纳的回答

Yifeng Tang
Yifeng Tang 2021-6-18
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 个评论
CCC
CCC 2021-6-22
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Equations 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by