Associate Traceability Information with MATLAB Code Lines in Simulink

Traceability management support in the MATLAB Editor is an extension of the Simulink-based Requirements Management Interface to allow associations between MATLAB code lines and external artifacts. This capability does not require editing MATLAB files; all traceability data is stored separately. This is similar to "external" storage of RMI links when working with Simulink models.

In addition, using "external storage" mode for managing traceability information, Simulink and Stateflow users can benefit from finer granularity when associating external documents with contents of MATLAB Function blocks.

The included example model has traceability data associated both with Simulink blocks and individual code lines of MATLAB Function blocks.

Open Example Model

This example demonstrates linking between external documents and MATLAB code lines when modeling stimulated spiking in connected neural cells.

Open the slvnvdemo_synaptic_transmission model. There are three Model blocks referencing the same model of a spiking neural cell. The neural cell model follows a "Leaky Integrators" equation:

For the purpose of simulation, we converted to:

Two MATLAB Functions between neurons calculate post-synaptic currents. When presynaptic depolarization crosses the neurotransmitter release threshold, we increment post-synaptic current by one pulse of given amplitude:

Resulting total current decays exponentially according to

We disallow the next increment for a certain timeframe after the previous pulse, to model the effect of short-term synaptic depression. Our model neglects the time delay of axonal transmission.


Simulate Model and View Results

Simulate slvnvdemo_synaptic_transmission model. Check Scope for results. The six plots are:

  • externally injected electrical current pulse,

  • injection-stimulated intracellular voltage spiking of the first neuron,

  • post-synaptic current generated in the second neuron,

  • synaptically stimulated activity of the second neuron,

  • post-synaptic current generated in the third neuron,

  • synaptically stimulated activity of the third neuron.

Observe regular spiking of the upstream neuron (plot 2) while stimulation pulse is applied (plot 1). Synaptically induced current in downstream neuron (plot 3) skips some action potentials of the upstream neuron due to short-term neurotransmitter depletion modeled as a temporary turn-off period in Synaptic current function. Downstream neuron is seen to, sometimes, integrate more than one synaptic input to produce a spike (plot 4). The third neuron integrates synaptic inputs from the second neuron (plot 5) and spikes at a later time (plot 6). With our default parameter values, the third neuron may spike 1 or more times, depending on intentionally introduced random noise in the model.

We assign same parameter values for all three neurons and both synapses. Traceability linking is used to justify parameter values and implementation.

### Successfully updated the model reference SIM target for model: slvnvdemo_neuron

Navigate Between Simulink and Standalone MATLAB Files

The slvnvdemo_synaptic_transmission model runs an external script to load required parameter values into workspace. MATLAB code linking allows you to trace from a dependent block in Simulink, not only to a script file but to the specific line that defines a value used in simulation.

Locate the Stimulation pulse block in the model. Right-click the block and select Requirements Traceability > 1. "I_inj = 2e-11; % 20 pA" to follow the link and view the relevant highlighted region in the MATLAB code file. Notice the mismatched value so easily detected via Traceability link. Right-click another highlighted line in the MATLAB file and navigate back to Simulink by selecting the shortcut in the Requirements Traceability context menu.

rmi('highlightModel', 'slvnvdemo_synaptic_transmission');

Create Traceability Link for Lines of MATLAB Code

The Synaptic time constant block in the bottom left corner of the model is not yet linked to its related line in parameters script.

Make sure that bidirectional linking is enabled, so that you can create two-way traceability links in one step. First, in the Simulink Editor, select the Synaptic time constant block. Then, in the MATLAB Editor, select the variable name Syn_decay_time at the bottom of the synaptic_params script. Right-click on the selected line and from the context menu, choose Requirements Traceability > Link to Selection in Simulink. Test the new links by navigating from MATLAB to Simulink and back to MATLAB.

Create Traceability Link for Lines of Code Inside MATLAB Function Blocks

The slvnvdemo_synaptic_transmission model has a MATLAB Function block that we will want to trace to parameter value sources. Instead of linking the block itself, open the MATLAB code of this block and link specific lines. For example, in the Simulink Editor, click on the Synaptic strength constant block to select it for linking. In the MATLAB Editor, find the occurrence of I_amplitude on line 33 of the MATLAB Function block code. Right-click the line and from the Requirements Traceability context menu, select Link to Selection in Simulink.

Create Traceability Link Between Lines in MATLAB Code and Microsoft Word

Until this point we only looked at linking between MATLAB and Simulink. Open the Ion current calculation MATLAB Function block that belongs to the Sodium current calculation subsystem of the referenced slvnvdemo_neuron model. Right-click on a highlighted line or lines and from the Requirements Traceability context menu, navigate a link at the top. The associated Word document opens to the associated text.

To create a similar link in another MATLAB Function block of this model, Ion current calculation Function in Potassium channel current subsystem, select the relevant content in the Word document (i.e. outward current of potassium ions). Then, open the Potassium channel current MATLAB Function block. In the MATLAB Editor, select the implementation for outwardCurrent subfunction (lines 34-37). Right-click the selected lines and in the context menu, select Requirements Traceability > Link to Selection in Word. Minimize the Word document, then navigate from the newly highlighted lines at the bottom of the MATLAB code to the related description in Word. When the correct location is highlighted, use the MATLAB icon to navigate back to code.

Report Traceability Links

Traceability links associated with MATLAB code lines of MATLAB Function blocks are included in the Requirements Traceability Report generated for the parent Simulink model. Use Analysis > Requirements Traceability > Generate Report in slvnvdemo_neuron model window to generate the report. See MATLAB Function block links information present in the report, including quotations of linked MATLAB Code lines.

Was this topic helpful?