Main Content


Assign code to Safety Analysis Manager spreadsheet callback

Since R2024a



setCallback(spreadsheet,callbackType,code) assigns the code, code, to the callback, callbackType, in the Safety Analysis Manager spreadsheet, spreadsheet.


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 + ...

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.


Input Arguments

collapse all

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

Callback type to assign the code to, specified as one of these values:

Callback TypeWhen Callback Executes
"PreLoadFcn"Before the spreadsheet loads
"PostLoadFcn"After the spreadsheet loads
"AnalyzeFcn"When you use the runAnalysis function or press F5. This corresponds to the default AnalyzeFcn callback. To set callback code for a custom callback, set callbackType to the custom callback name.
"PreSaveFcn"Before the spreadsheet is saved
"PostSaveFcn"After the spreadsheet is saved
"CloseFcn"Before the spreadsheet is closed
Custom callback nameIf the custom callback is enabled, it executes when you use the runAnalysis function or press F5. Create the custom callback by using the addCallback function.

Callback code, specified as a character vector or a string scalar.

Data Types: char | string

Version History

Introduced in R2024a