Main Content

runAnalysis

Execute callback script on Safety Analysis Manager spreadsheet

Since R2023b

Description

example

runAnalysis(spreadsheet) executes the scripts that you define in the default AnalyzeFcn and enabled custom AnalyzeFcn callbacks in the Safety Analysis Manager spreadsheet, spreadsheet. For more information on callbacks in the Safety Analysis Manager, see Create Callbacks.

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_spreadsheet.Rows" + newline + ...
"  textCell = getCell(sfa_spreadsheet,n,2);" + newline + ...
"  checkCell = getCell(sfa_spreadsheet,n,1);" + newline + ...
"  if checkCell.Value == 0" + newline + ...
"      addFlag(textCell,""warning"")" + newline + ...
"  end" + newline + ...
"end";

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

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

setCallback(mySpreadsheet,"AnalyzeFnc",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_spreadsheet.Rows" + newline + ...
"  textCell = getCell(sfa_spreadsheet,n,3);" + newline + ...
"  checkCell1 = getCell(sfa_spreadsheet,n,1);" + newline + ...
"  checkCell2 = getCell(sfa_spreadsheet,n,2);" + newline + ...
"  if checkCell1.Value == 0 || checkCell2.Value == 0" + newline + ...
"      addFlag(textCell,""warning"")" + newline + ...
"  end" + newline + ...
"end";

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

Create the second callback code as a string.

callBackString2 = "for n = 1:sfa_spreadsheet.Rows" + newline + ...
"  textCell = getCell(sfa_spreadsheet,n,3);" + newline + ...
"  checkCell1 = getCell(sfa_spreadsheet,n,1);" + newline + ...
"  checkCell2 = getCell(sfa_spreadsheet,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)

Input Arguments

collapse all

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

Version History

Introduced in R2023b