Main Content

CellReference

Referenced cell in Safety Analysis Manager spreadsheet

Since R2024b

Description

CellReference objects represent cells in Safety Analysis Manager spreadsheets that a cell references. References allow you to access spreadsheet cell values and use them in derived columns. For more information on references in Safety Analysis Manager spreadsheets, see Create References in Derived Column Cells. Use CellReference objects to get additional properties of the referenced cells.

Creation

To create a CellReference object, use the getReferences function on a SpreadsheetCell object. The SpreadsheetCell object must be in a derived column.

Properties

expand all

This property is read-only.

File path of the spreadsheet that contains the referenced cell, returned as a character vector.

Data Types: char

This property is read-only.

Row location of the referenced cell, returned as a positive integer. The row index of the leftmost column of the spreadsheet is 1.

Data Types: uint64

This property is read-only.

Column location of the referenced cell, returned as a positive integer. The row index of the topmost row of the spreadsheet is 1.

Data Types: uint64

This property is read-only.

Label of the column in the spreadsheet that contains the referenced cell, returned as a character vector.

Data Types: char

This property is read-only.

Value of the referenced cell, returned as a character vector, a numeric or logical 1 (true) or 0 (false), or an enumeration class value. The value type returned depends on the column type that contains the referenced cell:

Column TypeValue TypeMore Information
TextCharacter vectorAdd Rows and Columns to a Spreadsheet
Check BoxLogical 1 (true) or 0 (false)Create a Check Box Column
EnumerationCharacter vector or explicit value specified by an enumeration class
DerivedCharacter vector that contains the output of the column formulaCreate a Derived Column That Outputs Based on Two Column Values

Data Types: char | logical

Examples

collapse all

Create two Safety Analysis Manager spreadsheets, and store each Spreadsheet object in a variable.

mySpreadsheet1 = safetyAnalysisMgr.newSpreadsheet;
mySpreadsheet2 = safetyAnalysisMgr.newSpreadsheet;

Add three rows to each spreadsheet by using the addRow function.

addRow(mySpreadsheet1,Count=3)
addRow(mySpreadsheet2,Count=3)

Add a text column and derived column that have custom labels to the mySpreadsheet2 spreadsheet by using the addColumn function.

addColumn(mySpreadsheet2,Count=2,Type=["text","derived"]...
  ,Label=["Text Column","Derived Column"])

Save the spreadsheets.

save(mySpreadsheet1,"spreadsheet1.mldatx")
save(mySpreadsheet2,"spreadsheet2.mldatx")

Retrieve the SpreadsheetCell objects for the first cell in the mySpreadsheet1 spreadsheet and the first cell in the derived column in the mySpreadsheet2 spreadsheet.

myCell1 = getCell(mySpreadsheet1,1,1);
myCell2 = getCell(mySpreadsheet2,1,"Derived Column");

Create a reference where the myCell2 cell references the myCell1 cell by using the addReference function.

addReference(myCell2,myCell1)

Retrieve the CellReference object of the referenced cell by using the getReferences function on the myCell2 cell.

myReferencedCells = getReferences(myCell2);
myReferencedCells{1}
ans = 

  CellReference with properties:

       FileName: 'C:\spreadsheet2.mldatx'
            Row: 1
         Column: 1
    ColumnLabel: 'Label1'
          Value: ''

Version History

Introduced in R2024b