Main Content

moveReference

Change order of references

Since R2024b

Description

moveReference(spreadsheetCell,initialIndex,finalIndex) reassigns the Safety Analysis Manager spreadsheet reference that has the index, initialIndex, to the new index value, finalIndex. The cell, spreadsheetCell, contains the references.

When moveReference changes the index of a reference, the index of the references that are greater than or equal to the new index value and are less than the old index increase by one. The indexes of the other references do not change.

example

Examples

collapse all

Create two Safety Analysis Manager spreadsheets, and store each Spreadsheet objects 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 and derived column that have custom labels to the spreadsheet assigned to mySpreadsheet2 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 SperadsheetCell objects for the first three cells in the first column in the mySpreadsheet1 spreadsheet and the first cell in the derived column in the mySpreadsheet2 spreadsheet.

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

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

addReference(myCell2,myCell1)

Change the first reference to be the last reference.

moveReference(myCell2,1,numel(myCell1))

The second reference retains its index.

Input Arguments

collapse all

Spreadsheet cell to add the reference to, specified as a SpreadsheetCell object. The cell must be in a derived column. For more information on derived columns, see Define Derived Values and Define the Derived Column Formula.

Initial index of the reference, specified as a positive integer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

New index of the reference, specified as a positive integer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Version History

Introduced in R2024b