Main Content

Migrate from Signal Builder Block to Signal Editor Block

The Signal Builder block and the signalbuilder function are not recommended. Consider replacing the Signal Builder block with the Signal Editor block. For more information, see Replace Signal Builder Block with Signal Editor Block.

For programmatic access to the Signal Editor block, use the get_param and set_param functions. For more information, see Replace Programmatic Use of signalbuilder.

Replace Signal Builder Block with Signal Editor Block

The Signal Editor provides similar functionality to the Signal Builder block, but with greater flexibility. The benefits of the Signal Editor block include:

  • Signal data storage in a MAT-file outside the model

  • Signal editing and creation

  • Support for Simulink® signal attributes, such as dimension and complexity

  • Support for standard Simulink data types, including bus and fixed-point

  • Unique signal-level data types for outputs

  • Multiple rates for outputs

  • Support for Simulink units

  • Zero-Crossing Detection and data interpolation unique to each signal

To port signal data and properties from the Signal Builder block to the Signal Editor block, use the signalBuilderToSignalEditor function. For the current model, this function stores to a MAT-file the signal data and properties from an existing Signal Builder block, adds a Signal Editor block to the current model, and modifies the Signal Editor block to reference the new MAT-file.

Alternatively, to replace Signal Builder blocks with Signal Editor blocks, use the Check model for Signal Builder blocks Upgrade Advisor check.

For an example, see Replace Signal Builder Block with Signal Editor Block.

Considerations

When you convert from the Signal Builder block to the Signal Editor block, take into account these considerations:

  • Internal storage format and preprocessing of data differs between the Signal Builder and Signal Editor blocks. When using the variable step solver, different simulation time steps and mismatched output occur in the two blocks. To minimize the difference between the outputs of both blocks, you can:

    • Reduce the value of Max step size of the variable step solver.

    • Insert more data points in the input signal of the Signal Editor block to better represent its shape.

    • Use the fixed-step solver or set the sample time for both blocks to the same discrete sample time (greater than 0). For more information on discrete sample times, see Discrete Sample Times.

  • The Signal Builder block supports only doubles. To change the data type or other signal properties after conversion, click the button in the Signal Editor block to access the Signal Editor user interface.

  • Scenario names must comply with valid MATLAB® Variable Names.

Replace Programmatic Use of signalbuilder

The Signal Builder block and the signalbuilder function are not recommended. After replacing the Signal Builder block with the Signal Editor block, you can programmatically interact with the block using the get_param and set_param functions. These tables list the signalbuilder function and its equivalent functionality with get_param, set_param, and supporting code.

Replace Group Usage with Scenarios

ActionBlockProgrammatic Equivalents

Get scenario (group) names.

Signal Builder

[~,~,~,groupNames] = signalbuilder(hBlk);

Signal Editor

groupNames = get_param(hBlk,”options@ActiveScenario”); 

Get number of scenarios (groups).

Signal Builder

[~,~,~,groupNames] = signalbuilder(hBlk);
numGroups = length(groupNames);

Signal Editor

numGroups = str2double(get_param(hBlk,"NumberofScenarios"));

Get active scenario (group).

Signal Builder

[idx, name] = signalbuilder(hBlk,'activegroup');

Signal Editor

name = get_param(hBlk,"ActiveScenario")
groupNames = get_param(hBlk,”options@ActiveScenario”);
idx = find(strcmp(groupNames,name));

Set active scenario (group) by index.

Signal Builder

signalbuilder(hBlk,'activegroup',2);

Signal Editor

set_param(hBlk,"ActiveScenario",2)

Set active scenario (group) by name.

Signal Builder

N/A

Signal Editor

set_param(hBlk,"ActiveScenario",'Hard_braking')

Access Signals in Signal Editor and Signal Builder

ActionBlockProgrammatic Equivalents

Get signal names.

Signal Builder

[~,~,signalNames,~] = signalbuilder(hBlk);

Signal Editor

signalNames = get_param(hBlk,”options@ActiveSignal”);

Get number of signals in active scenario (group).

Signal Builder

[~,~,signalNames,~] = signalbuilder(hBlk); 
numSignals = length(signalNames);

Signal Editor

numSignals = get_param(hBlk,"NumberofSignals");

Get active signal.

Signal Builder

N/A

Signal Editor

name = get_param(hBlk,"ActiveSignal")

Set active signal by index.

Signal Builder

N/A

Signal Editor

set_param(hBlk,"ActiveSignal",2)

Set active signal by name.

Signal Builder

N/A

Signal Editor

set_param(hBlk,"ActiveSignal",'Throttle')

Create Signal Editor in Model

ActionBlockProgrammatic Equivalents

Add block to model.

Signal Builder

% Given array for time and data
hBlk = signalbuilder([gcs,'/Signal Builder'],'create',...
       time,data);

Signal Editor

% Given Simulink.SimulationData.Dataset, ds 
fileName = 'scenarioMatFile.mat'; 
save(fileName,'ds'); 
hBlk = add_block('simulink/Sources/Signal Editor', ...
       [gcs,'/Signal Editor'],'MakeNameUnique','on', ...
       'FileName',fileName);

Access Time and Data in Signal Editor Block

Because the Signal Editor block stores its data in a MAT-file that is external to the model, the programmatic equivalents are less direct than in the Signal Builder block for getting and setting time and data. In these cases, you must get the time and data in Signal Builder format using code like this:

% Get MAT-file name, number of groups, and group names.
fileName = get_param(hBlk,"FileName");
numGroups = str2double(get_param(hBlk,"NumberofScenarios"));
groupNames = get_param(hBlk,"options@ActiveScenario"); 
% Load groups from MAT-file.
load(fileName);
time = {};
data = {};
% Get time and data from groups.
for id = 1:numGroups
    ds = eval(groupNames{id});
    timeThisScenario = {};
    dataThisScenario = {};
    for elementId = 1:ds.numElements
        % Timeseries in Simulink.SimulationData.Dataset, ds
        timeThisScenario{end+1} = ds{elementId}.Time';
        dataThisScenario{end+1} = ds{elementId}.Data';
    end
    % Put time and data into Signal Builder format.
    time(1:length(timeThisScenario),id) = timeThisScenario;
    data(1:length(dataThisScenario),id) = dataThisScenario;
end
ActionBlockProgrammatic Equivalents

Get time and data in Signal Builder format.

Signal Builder

[time, data] = signalbuilder(hBlk);

Signal Editor

Use the code Access Time and Data in Signal Editor Block to get the time and data and then convert desired signals to Signal Builder time and data formats.

Get last time for data.

Signal Builder

time = signalbuilder(hBlk);
endTime = time{1,1}(end);

Signal Editor

Use the code in Access Time and Data in Signal Editor Block to get the time and data in Signal Builder format and then find the maximum time value for all time values.

Get time and data for specific signal.

Signal Builder

[time,data] = signalbuilder(hBlk,'get',signalNames{sigId},groupNames)

Signal Editor

Use the code in Access Time and Data in Signal Editor Block to get the time and data and then convert desired signals to Signal Builder time and data formats.

Set time and data to empty (delete) for all signals and groups. Both return error.

Signal Builder

signalbuilder(hBlk,'set',1:1:numSignals,1:1:numGroups,[]);

Signal Editor

fileName = get_param(hBlk,’FileName’);
ds = Simulink.SimulationData.Dataset;
save(fileName, 'ds');

Set time and data to empty (delete) for specific signals and groups.

Signal Builder

signalbuilder(hBlk,'set',[1,2],1,[],[])

Signal Editor

Use the code in Access Time and Data in Signal Editor Block to get the time and data and then set the desired signals with updated time and data and save the MAT-file in append mode.

Append Scenarios and Groups

ActionBlockProgrammatic Equivalents

Add scenarios (groups).

Signal Builder append

time = {timeNew1 timeNew1; timeNew2 timeNew2};
data = {dataNew1 dataNew1; dataNew2 dataNew2};
[~,~,signalNames,~] = signalbuilder(hBlk);
signalbuilder(hBlk, 'append', time, data, signalNames, groupNames);

Signal Builder append group

time = {timeNew1 timeNew1; timeNew2 timeNew2};
data = {dataNew1 dataNew1; dataNew2 dataNew2};[~,~,signalNames,~] = signalbuilder(hBlk); 
signalbuilder(hBlk, 'appendgroup', time, data, signalNames, groupName);

Signal Editor

% Convert time and data formats to signals.  
newSignal(1) = timeseries(dataNew1', timeNew1');
newSignal(2) = timeseries(dataNew2', timeNew2'); 
% Get MAT-file name.  
fileName = get_param(hBlk,"FileName");
% Load groups from MAT-file.  
load(fileName);
% Add new scenarios (groups). 
numGroups = length(groupNames);
numSignals = str2double(get_param(hBlk,"NumberofSignals"));
signalNames = get_param(hBlk,"options@ActiveSignal");
for id = 1:numGroups
    % create new dataset
    ds(id) = Simulink.SimulationData.Dataset;
    for idSig = 1:numSignals
        element = Simulink.SimulationData.Signal;
        element.Name = signalNames{idSig};
        element.Values = newSignal(idSig);
        ds(id) = addElement(ds(id),element);
    end
    assignin('caller', groupNames{id}, ds(id));
    % Save MAT-file using append mode.
    save(fileName, groupNames{id}, '-append');
end  

Append Signals

ActionBlockProgrammatic Equivalents

Add signal to all scenarios (groups).

Signal Builder

time = {timeNew1 timeNew1; timeNew2 timeNew2};
data = {dataNew1 dataNew1; dataNew2 dataNew2};
signalNames = {'signalNew1', 'signalNew2'};
signalbuilder(hBlk, 'appendsignal', time, data, signalNames);

Signal Editor

% Convert time and data formats to signals.  
newSignal(1) = timeseries(dataNew1', timeNew1');
newSignal(2) = timeseries(dataNew2', timeNew2'); 
% Get MAT-file name.  
fileName = get_param(hBlk,"FileName");
% Load groups from MAT-file.  
load(fileName);
% Use unique signal names.
signalNames = {'signalNew1', 'signalNew2'}; 
% Append signals to scenarios (groups). 
numGroups = length(groupNames);
numSignals = length(signalNames);
for id = 1:numGroups
    % Get dataset.
    ds = eval(groupNames{id});
    for idSig = 1:numSignals
        element = Simulink.SimulationData.Signal;
        element.Name = signalNames{idSig};
        element.Values = newSignal(idSig);
        ds = addElement(ds,element);
    end
    assignin('caller', groupNames{id}, ds);
    % Save MAT-file using append mode.
    save(fileName, groupNames{id}, '-append');
end

Print

ActionBlockProgrammatic Equivalents

Print to Handle Graphics® figure.

Signal Builder

hFig = signalbuilder(hBlk,'print',config,'figure');

Signal Editor

Use the code in Access Time and Data in Signal Editor Block to get the signals from the dataset and then plot the desired data.

See Also

Functions

Blocks

Tools