Main Content

Safety Analysis Manager

Create and edit documents for safety analyses

Since R2023b

Description

Use the Safety Analysis Manager app to create documents used for safety analyses, such as Failure Mode and Effects Analyses (FMEAs) and Functional Hazard Assessments (FHAs). Link elements in spreadsheets to model artifacts such as requirements and faults.

This image shows the Safety Analysis Manager. The Safety Analysis Manager has an untitled spreadsheet loaded with two rows and five columns. The first three columns are empty, and the last two columns have empty check boxes.

Open the Safety Analysis Manager App

  • MATLAB® Toolstrip (since R2024b): On the Apps tab, in the Apps section, under Model Verification, Validation, and Test, click Safety Analysis Manager.

  • Simulink® Toolstrip: On the Apps tab, under Model Verification, Validation, and Test, click Safety Analysis Manager.

  • Fault Analyzer tab: In the Management section, click Safety Analysis Manager.

Examples

expand all

You can create a new spreadsheet by creating an empty spreadsheet or using a template that has specified columns and column types. To create a spreadsheet:

  1. In the Safety Analysis Manager, in the File section, click New.

  2. Create an empty spreadsheet by clicking Empty Spreadsheet. Alternatively, open a template in the From Template section. If you select Custom Template, you must select a MLDATX template file.

To open a spreadsheet, in the File section, click Open. You can also press Ctrl+O if you are already in a spreadsheet. You must select a MLDATX spreadsheet file.

To create a spreadsheet using external files, such as an Excel® file, in the File section, click Import. For more information on importing spreadsheets from Excel, see Import Excel Files into the Safety Analysis Manager.

To add a row to a spreadsheet, in the Spreadsheet section, click Add Row. To add a new column, in the Spreadsheet section, click Add Column. You can also add rows and columns with these modifications:

  • If you select a row and click Add Row, the spreadsheet adds the new row below the selected row.

  • If you select a row and click Add Column, the spreadsheet adds the new column to the right of the selected column.

  • If you select more than one row or column and click Add Row or Add Column, the spreadsheet adds an equal number of rows or columns to the spreadsheet. For example, if you select three rows and click Add Row, the spreadsheet adds three rows.

Rows automatically adjust to the height of the content in their cells. You can adjust the width of the columns manually.

To delete a row, click on the row index and, in the Edit section, click Delete.

To delete a column, click on the column label and, in the Edit section, click Delete.

Since R2024a

By default, columns are visible in Safety Analysis Manager spreadsheets. To hide columns:

  1. Open an existing spreadsheet or create a new spreadsheet with at least two columns.

  2. In the Spreadsheet section, click View Columns.

  3. In the View Columns window, clear the columns that you want to hide and click OK.

Hidden columns retain their index, and you can still access their content by using programmatic options. For more information on programmatic options, see Spreadsheet and Create and Configure Safety Analysis Manager Spreadsheets Programmatically.

Safety Analysis Manager spreadsheets must have at least one visible column.

By default, the Add Column button creates a text column. You can specify the type of column as you create it or after you add it.

To create a new check box column:

  1. Open an existing spreadsheet or create a new spreadsheet.

  2. In the Spreadsheet section, click Add Column.

  3. Right-click the column label to access the context menu and click Column Type > Checkbox.

You can also change the column type after you set it from the context menu.

To create an enumeration column, define an enumeration class definition file on path. See Define Enumeration Classes. Then, specify an enumeration column and assign the enumeration class to the column. The entries in the column are limited to the entries in the class definition.

For example, to create an enumeration column that specifies a day out of the week:

  1. In a new MATLAB file, define an enumeration class named WeekDays.

    classdef WeekDays
       enumeration
          Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
       end
    end

    Save the class definition on your file path with the name WeekDays.m.

  2. In the Safety Analysis Manager, open an existing spreadsheet or create a new spreadsheet.

  3. In the Spreadsheet section, click Add Column.

  4. Right-click the column label to access the context menu and click Column Type > Enumeration.

  5. In the Enumeration Class window, enter the name of the class, WeekDays, and click OK.

In the column, double-click a cell to expand the available values.

A spreadsheet with an enumeration column that uses the WeekDays class definition. The seven days of the week are available, and the cursor points to Monday.

Click the value to set the cell value.

You can create derived columns that uses MATLAB code to retrieve information from the spreadsheet and adjust the column cell values. The information that you retrieve is read-only.

Suppose you have a spreadsheet with two text columns, Column1 and Column2, and you want to create a column that takes the strings in those columns and creates a new string. Create a derived column.

  1. In the Spreadsheet section, click Add Column.

  2. Right-click the column label to access the context menu and click Column Type > Derived.

  3. Right-click the column label and click Edit Formula.

  4. In the Column Formula Editor window, retrieve the adjacent values of the column cells by using the sfa_columnValue operator, and assigning the new string to the cell by using the sfa_derivedCell keyword:

    x = sfa_columnValue("Column1");
    y = sfa_columnValue("Column2");
    sfa_derivedValue = x + " " + y;
  5. Close the Column Formula Editor window. The column now derives its cells from the adjacent cell values in Column1 and Column2.

To add a description to a spreadsheet:

  1. Open or create a new Safety Analysis Manager spreadsheet.

  2. In the Properties pane, in the Spreadsheet tab, add a description in the Description section.

To add a description to a row (since R2024b):

  1. Click a row number in the spreadsheet.

  2. In the Properties pane, in the Row tab, add a description in the Description section.

To add a description to a cell in a spreadsheet:

  1. Click a cell in the spreadsheet.

  2. In the Properties pane, in the Cell tab, add a description in the Description section.

If you have Requirements Toolbox™, you can link spreadsheet cells (since R2023b) and rows (since R2024b) to other model artifacts, including blocks, test cases, and faults. For example, to link a cell to a fault:

  1. In a model with faults, in the Apps tab, click Fault Analyzer.

  2. In the Fault Analyzer tab, in the View section, click Fault Table.

  3. In the Fault Table pane, click the Fault tab.

  4. Expand the model element list and click the fault that you want to link.

  5. In a saved Safety Analysis Manager spreadsheet that contains at least one cell, click the cell.

  6. In the Links section, click Add Link > Link to Selection in Fault Table.

For more information on linking spreadsheet cells and rows to other model artifacts, see Link Safety Analysis Manager Spreadsheet Cells and Rows to Linkable Items.

This example shows how to create references in a derived column cell to cells in a different spreadsheet. For more information on creating references, see Create References in Derived Column Cells.

Open Spreadsheets

Open the Safety Analysis Manager and the qualityChecks and qualityRanks spreadsheets.

safetyAnalysisMgr.openManager
safetyAnalysisMgr.openDocument("qualityRanks.mldatx");
safetyAnalysisMgr.openDocument("qualityChecks.mldatx");

The qualityChecks spreadsheet has a derived column named Quality Evaluation.

the qualityChecks spreadsheet. The spreadsheet contains three rows and three columns. The column labels, from left to right, are Metric 1, Metric 2, and Quality Evaluation. The Metric 1 and Metric 2 columns are check box columns, and the Quality Evaluation column is a derived column. The Metric 1 column check boxes are not selected, and the second check box in the Metric 2 column is selected. The Quality Evaluation column has different text in each cell.

Click the cells in the derived column to view the references that each cell contains. In the Properties pane, in the Cell tab, expand the References section. The first two cells in the derived column reference the values in the qualityRanks spreadsheet, but the third cell does not. This image shows the references in the second cell.

The references in the second cell in the derived column. The cell has three references. They reference the qualityRanks spreadsheet. The references include the referenced cells. Each referenced cell displays their corresponding row index and column label.

Open the derived column formula to view the code. Right-click the column label and click Edit Formula. The formula retrieves the values from the Metric 1 and Metric 2 columns and uses these values to output the value of the referenced cell based on this logic:

  • If the derived column cell does not have references, the value of the derived column cell is Add references to QualityRanks spreadsheet cells.

  • If the derived column cell has references, but none of the values in the Metric 1 or Metric 2 columns are true, the derived column cell uses the first referenced cell value.

  • If the derived column cell has references, but only one of the values in the Metric 1 or Metric 2 columns is true, the derived column cell uses the second referenced cell value.

  • If the derived column cell has references, and both values in Metric 1 or Metric 2 columns is true, the derived column cell uses the third referenced cell value.

metric1 = sfa_columnValue("Metric 1");
metric2 = sfa_columnValue("Metric 2"); 

refValues = sfa_referencedValues;

if numel(refValues) == 0
    sfa_derivedValue = ...
        "Add references to QualityRanks spreadsheet cells";
elseif metric1 == true && metric2 == true
    sfa_derivedValue = ...
         "Quality rating: " + sfa_referencedValues{1};
elseif metric1 == true || metric2 == true
    sfa_derivedValue = ...
        "Quality rating: " + sfa_referencedValues{2};
else
    sfa_derivedValue = ...
        "Quality rating: " + sfa_referencedValues{3};
end

Create References

In this example, create references such that the third cell in Quality Evaluation column references the cells in the qualityRanks spreadsheet.

  1. In the qualityRanks spreadsheet, select the cells in the Quality Ranks column.

  2. In the Spreadsheet section, click Add Reference > Select for Referencing.

  3. In the qualityChecks spreadsheet, select the third cell in the derived column.

  4. in the Spreadsheet section, click Add Reference > Create Reference to Selection.

The qualityChecks spreadsheet now has references in the third derived column cell.

The new references shown in the Properties pane. The cursor points to and has selected the third cell in the Quality Evaluation column.

Click the check boxes in the Metric 1 and Metric 2 columns to update the output of the derived column cell. Similarly, if you adjust the values in the qualityRanks spreadsheet, the derived column also updates the cells that contain the references.

To find cells containing specified text:

  1. Open an existing spreadsheet or create a new spreadsheet.

  2. In the Search section, click Find or press Ctrl+F. The search bar opens.

  3. Enter the text that you want to find. You can specify if the search is case sensitive and if it searches for only whole cell content matches. The search highlights the matching text in the cells in yellow.

You can use callbacks to run MATLAB scripts when you do tasks like loading, analyzing, saving, or closing a document. To create a callback:

  1. Open a document.

  2. In the Analyze section, click Edit Callbacks. The Callbacks Editor window opens.

  3. Enter your code in one or more of these callback types:

    Callback TypeWhen Callback Executes
    PreLoadFcnBefore the spreadsheet loads
    PostLoadFcnAfter the spreadsheet loads
    AnalyzeFcnWhen you click Analyze Spreadsheet or press F5
    PreSaveFcnBefore the spreadsheet is saved
    PostSaveFcnAfter the spreadsheet is saved
    CloseFcnBefore the spreadsheet is closed

  4. Exit the Callbacks Editor window to save the callbacks.

For more information, see Write Callbacks to Analyze Safety Analysis Manager Documents.

The AnalyzeFcn callback type includes a default callback that is always enabled. You can also add custom AnalyzeFcn callbacks that you can enable or disable (since R2024a). See Create and Select Custom Callbacks for Safety Analysis Manager Documents.

This example shows how to refresh derived cell values after you update an externally called MATLAB® function.

Inspect the Spreadsheet

Open the Safety Analysis Manager and the spreadsheet, myRefreshedSheet.

safetyAnalysisManager
mySheet = safetyAnalysisMgr.openDocument("myRefreshedSheet.mldatx");

The Calculation column calls the external MATLAB function, myCalculationFunction, to multiply the values in the Input 1 and Input 2 columns, and outputs the result.

The myRefreshedSheet spreadsheet. The spreadsheet has three columns and three rows. The Calculation column multiplies the values in the Input 1 and Input 2 columns together. The Calculation column is grey, and the others are white.

Open the myCalculatorFunction MATLAB file to view the code.

open("myCalculatorFunction")
function output = myCalculatorFunction(x,y)
    output = str2double(x) * str2double(y);
    output = num2str(output);
end

Update Calculations and Refresh Spreadsheet Cell Values

Change the myCalculationFunction function to add the two numbers.

function output = myCalculatorFunction(x,y)
    output = str2double(x) + str2double(y);
    output = num2str(output);
end

Save the function and return to the Safety Analysis Manager spreadsheet. The cell values are not updated. To call the updated function and recalculate the cell values, in the Spreadsheet section, click Refresh Values. The spreadsheet updates the calculated values in the Calculation column.

The myRefreshedSheet spreadsheet. The spreadsheet has three columns and three rows. The Calculation column adds the values in the Input 1 and Input 2 columns together. The Calculation column is grey, and the others are white.

To programmatically refresh the cell values, use the refreshDerivedValues function.

The Diagnostics pane lists diagnostics from the scripts that you create in callbacks. The pane displays the same types of diagnostic messages that appear in the Diagnostic Viewer in Simulink models. See Diagnostic Viewer. You can use filters to display errors, warnings, or information.

  1. At the bottom of the Safety Analysis Manager, expand the Diagnostics pane by clicking the Expand Bottom button .

  2. To display:

    • Information — Click the Show/Hide information button .

    • Warnings — Click the Show/Hide warnings button .

    • Errors — Click the Show/Hide errors button .

The pane displays the number of each kind of diagnostic message next to the corresponding button. Each message links to the document that contains the diagnostic.

To clear the diagnostics, click the Clear all diagnostics button .

After generating diagnostics, you can export them to a separate TXT file. To export diagnostics:

  1. At the bottom of the Safety Analysis Manager, expand the Diagnostics pane by clicking the Expand Bottom button .

  2. Click the Export diagnostics button .

  3. Save the diagnostics as a TXT file.

To export a spreadsheet to Excel:

  1. Open an existing spreadsheet.

  2. In the Share section, click Export.

  3. Save the file. When running Simulink in Windows®, you can save the file with the .xls, .xlsb, .xlsm, or .xlsx extension. When running Simulink in macOS or Linux®, you can save the file with the .xls, .xlsm, or .xlsx extension.

To create document attributes:

  1. Open an existing spreadsheet or create a new spreadsheet.

  2. In the Properties pane, in the Spreadsheet tab, in the Document attributes section, click the Add new document attribute button .

To delete a document attribute, select the attribute and click the Delete document attribute button .

Related Examples

Programmatic Use

expand all

safetyAnalysisMgr.openManager opens the Safety Analysis Manager app.

safetyAnalysisManager opens the Safety Analysis Manager app.

Version History

Introduced in R2023b

expand all

See Also