Code covered by the BSD License  

Highlights from
Find Logged Signals

image thumbnail
from Find Logged Signals by Cole Stephens
Find all test-pointed & logged signals in the current Simulink model.

Logged_Signal_Names(varargin)
function y = Logged_Signal_Names(varargin)
%% Finds all testpointed (& logged) signals in the current system.
% The optional input allows the user to turn the data logging on or off for
% all testpointed signals.
% e.g.
% Logged_Signal_Names
%   Will return a cell array of structures with the names of all
%   testpointed data.
% Logged_Signal_Names('off')
%   Will also return the same cell array as above, but will additionally
%   turn data logging off for all testpointed signals.
% Logged_Signal_Names('on')
%   Will also return the same cell array as above, but will additionally
%   turn data logging on for all testpointed signals.

%% Check to see if a block diagram is open
    if isempty(gcs)
        disp('There are no Simulink diagrams open.');
        return;
    end
    
%% Initialize some variables
TestedSignalNames{1} = 'None';

%%  Get a list of all the blocks in the current system.
Blocks = find_system(gcs, 'regexp', 'on', 'blocktype','.*');
hdlBlocks = get_param(Blocks, 'handle');

%% Trim the list to just "testpointed" signals
ctr=0;
for idx = 1:length(hdlBlocks)
    % testpointing is tied to ports...so find all the ports, specifically
    % the output ports.
    dummy = get_param(hdlBlocks{idx},'PortHandles');
    dummy = dummy.Outport;
    
    % Check to see if any of the output ports are set for testpointing.
    for jdx = 1:length(dummy)
        if ~isempty(dummy(jdx))
            % FYI, all logged signals are also testpointed.
            if  strcmp(get_param(dummy(jdx),'testpoint'),'on')     
                ctr = ctr + 1;
                TestedSignalNames{ctr}.Handle = dummy(jdx);
                TestedSignalNames{ctr}.Name = ...
                    get_param(dummy(jdx),'name');
                % Check specifically to see if Data Logging is on.
                if strcmp(get_param(dummy(jdx),'datalogging'),'on')
                    TestedSignalNames{ctr}.GonnaLog = 'Yep';
                else
                    TestedSignalNames{ctr}.GonnaLog = 'Nope';
                end
                TestedSignalNames{ctr}.LoggingName = ...
                    get_param(dummy(jdx),'dataloggingname');
            end %if
        end %if
    end %jdx
end %idx

%% Check for arguments...
if nargin > 0
    if strcmpi(varargin{1},'yes')
        for idx=1:length(TestedSignalNames)
            set_param(TestedSignalNames{idx}.Handle,'datalogging','on');
        end
    elseif strcmpi(varargin{1},'no')
        for idx=1:length(TestedSignalNames)
            set_param(TestedSignalNames{idx}.Handle,'datalogging','off');
        end
    else
        disp('Enter a valid string (''yes'' or ''no'').');
    end
end
    
%% Done
y = TestedSignalNames;

Contact us at files@mathworks.com