メインコンテンツ

runAnalysis

R2026b

Execute callback script on Safety Analysis Manager document

Since R2023b

Description

runAnalysis(spreadsheet) executes the default and enabled custom AnalyzeFcn callback scripts in the Safety Analysis Manager spreadsheet, spreadsheet. For more information on callbacks in Safety Analysis Manager spreadsheets, see Write Callbacks to Analyze Safety Analysis Manager Spreadsheets.

example

runAnalysis(faultTreeDocument) executes the default and enabled custom AnalyzeFcn callback scripts in the Safety Analysis Manager fault tree document, faultTreeDocument. For more information on callbacks in the Safety Analysis Manager fault tree documents, see Write Callbacks to Analyze Safety Analysis Manager Fault Tree Documents. (since R2026b)

example

Examples

collapse all

Suppose you have one Safety Analysis Manager spreadsheet open, mySpreadsheet.mldatx, and it has two columns. The first is a check box column and the second is a text column. You want to write a callback script where, if the check box for a cell is not selected, you mark the adjacent cell in the text column with a warning flag.

Retrieve the Spreadsheet object of the spreadsheet.

mySpreadsheet = safetyAnalysisMgr.getOpenDocuments;

Create the callback code as a string.

callBackString = "for n = 1:sfa_document.Rows" + newline + ...
"  textCell = getCell(sfa_document,n,2);" + newline + ...
"  checkCell = getCell(sfa_document,n,1);" + newline + ...
"  if checkCell.Value == 0" + newline + ...
"      addFlag(textCell,""warning"");" + newline + ...
"  end" + newline + ...
"end";

The code uses the sfa_document keyword to retrieve the Spreadsheet object of the spreadsheet that contains this script.

Before R2026b: To retrieve the Spreadsheet object in a Safety Analysis Manager callback, use the sfa_spreadsheet keyword.

Assign the code to the default AnalyzeFcn callback by using the setCallback function.

setCallback(mySpreadsheet,"AnalyzeFcn",callBackString)

Run the callback script.

runAnalysis(mySpreadsheet)

Since R2024a

Suppose you have one Safety Analysis Manager spreadsheet open, mySpreadsheet.mldatx, and it has three columns. The first two columns are check box columns and the third is a text column. You want to write two callback scripts:

  • For the first callback, if the cell in the first or second column is not selected, add a warning flag to the cell in the text column.

  • For the second callback, if neither cell is selected, add an error flag to the cell in the text column.

In this example, execute only the first callback when you analyze the spreadsheet.

Retrieve the Spreadsheet object of the spreadsheet.

mySpreadsheet = safetyAnalysisMgr.getOpenDocuments;

Create the first callback code as a string.

callBackString1 = "for n = 1:sfa_document.Rows" + newline + ...
"  textCell = getCell(sfa_document,n,3);" + newline + ...
"  checkCell1 = getCell(sfa_document,n,1);" + newline + ...
"  checkCell2 = getCell(sfa_document,n,2);" + newline + ...
"  if checkCell1.Value == 0 || checkCell2.Value == 0" + newline + ...
"      addFlag(textCell,""warning"");" + newline + ...
"  end" + newline + ...
"end";

The code uses the sfa_document keyword to retrieve the Spreadsheet object of the spreadsheet that contains this script.

Before R2026b: To retrieve the Spreadsheet object in a Safety Analysis Manager callback, use the sfa_spreadsheet keyword.

Create the second callback code as a string.

callBackString2 = "for n = 1:sfa_document.Rows" + newline + ...
"  textCell = getCell(sfa_document,n,3);" + newline + ...
"  checkCell1 = getCell(sfa_document,n,1);" + newline + ...
"  checkCell2 = getCell(sfa_document,n,2);" + newline + ...
"  if checkCell1.Value == 0 && checkCell2.Value == 0" + newline + ...
"      addFlag(textCell,""error"");" + newline + ...
"  end" + newline + ...
"end";

Create two custom callbacks of the AnalyzeFcn callback type by using the addCallback function.

addCallback(mySpreadsheet,"callback1")
addCallback(mySpreadsheet,"callback2")

Assign the code to the custom callbacks by using the setCallback function.

setCallback(mySpreadsheet,"callback1",callBackString1)
setCallback(mySpreadsheet,"callback2",callBackString2)

Enable the first custom callback and disable the second by using the enableCallback function.

enableCallback(mySpreadsheet,["callback1","callback2"],[1,0])

Run the enabled custom callback script.

runAnalysis(mySpreadsheet)

Since R2026b

Suppose you have one Safety Analysis Manager fault tree document open, mySpreadsheet.mldatx. You want to check that each event in the fault tree document uses a unique failure model. If the assigned failure model is not shared, add a check flag to the event. If the assigned failure model is shared, add an error flag to the event.

Retrieve the FaultTreeDocument object of the fault tree document.

myFaultTreeDoc = safetyAnalysisMgr.getOpenDocuments;

Create the callback code as a string.

callBackString = "for n = 1:numel(sfa_document.Events)" + newline + ...
"   checkEvent = sfa_document.Events(n);" + newline + ...
"   if sfa_document.Events(n).FailureModel.Shared == 0" + newline + ...
"       addFlag(sfa_document.Events(n),""check"")" + newline + ...
"   else" + newline + ...
"       addFlag(sfa_document.Events(n),""error"")" + newline + ...
"    end" + newline + ...
"end";

Assign the code to the default AnalyzeFcn callback by using the setCallback function.

setCallback(myFaultTreeDoc,"AnalyzeFcn",callBackString)

Run the callback script.

runAnalysis(myFaultTreeDoc)

Input Arguments

collapse all

Spreadsheet in the Safety Analysis Manager, specified as a Spreadsheet object.

Fault tree document in the Safety Analysis Manager, specified as a FaultTreeDocument object.

Version History

Introduced in R2023b

expand all