Main Content

addstate

Add one or more states to graph

Since R2024a

Description

example

stateIDs = addstate(graph,states) adds one or more states to the input graph specified as a navGraph object. Use this syntax if the states table of the input graph contain only one column representing the state vectors.

example

stateIDs = addstate(graph,states,metadata1,...metadataN) adds one or more states and the associated metadata information to the input graph specified as a navGraph object. Use this syntax if the states table of the input graph contain multiple columns that include metadata such as Names, in addition to the state vectors. However, the first column of the table must always specify the state vectors.

Examples

collapse all

Load navGraph object into MATLAB® workspace and inspect its properties.

load("navGraphStates.mat")
disp(navGraphObj)
  navGraph with properties:

           States: [8x1 table]
            Links: [7x3 table]
    LinkWeightFcn: @nav.algs.distanceEuclidean

Inspect the states table of the graph. You can notice that the state table has only one column, which contains the state vectors.

disp(navGraphObj.States)
          StateVector      
    _______________________

    8          2    0.72176
    1          1    0.29188
    7          7    0.91777
    8         10    0.71458
    5          1    0.54254
    3          6    0.14217
    2          9    0.37334
    8          7    0.67413

Add a state to the input graph by specifying the state vector. The addstate function returns the index of the new state in the states table.

Id = addstate(navGraphObj,[2 9 0.5])
Id = 9

Inspect the updated states table for new state.

disp(navGraphObj.States)
          StateVector      
    _______________________

    8          2    0.72176
    1          1    0.29188
    7          7    0.91777
    8         10    0.71458
    5          1    0.54254
    3          6    0.14217
    2          9    0.37334
    8          7    0.67413
    2          9        0.5

Load navGraph object into MATLAB® workspace and inspect its properties.

load("navGraphData.mat")
disp(navGraphObj)
  navGraph with properties:

           States: [8x3 table]
            Links: [7x3 table]
    LinkWeightFcn: @nav.algs.distanceEuclidean

Inspect the state table of the input graph. Note that the state table contains 'Name' and 'Lanes' metadata, in addition to the state vectors.

disp(navGraphObj.States)
          StateVector          Name     Lanes
    _______________________    _____    _____

    8          2    0.72176    {'A'}      2  
    1          1    0.29188    {'B'}      2  
    7          7    0.91777    {'C'}      2  
    8         10    0.71458    {'D'}      2  
    5          1    0.54254    {'E'}      2  
    3          6    0.14217    {'F'}      2  
    2          9    0.37334    {'G'}      3  
    8          7    0.67413    {'H'}      2  

Add two new states to the input graph. You must specify the 'Name' and 'Lanes' metadata, in addition to the state vectors. The addstate function returns the indices of the new states in the state table.

Id = addstate(navGraphObj,[8 8 0.6;5 7 0.5],{"I";"J"},[2;3])
Id = 2×1

     9
    10

Inspect the updated states table for new states and the related metadata.

disp(navGraphObj.States)
          StateVector          Name     Lanes
    _______________________    _____    _____

    8          2    0.72176    {'A'}      2  
    1          1    0.29188    {'B'}      2  
    7          7    0.91777    {'C'}      2  
    8         10    0.71458    {'D'}      2  
    5          1    0.54254    {'E'}      2  
    3          6    0.14217    {'F'}      2  
    2          9    0.37334    {'G'}      3  
    8          7    0.67413    {'H'}      2  
    8          8        0.6    {'I'}      2  
    5          7        0.5    {'J'}      3  

Input Arguments

collapse all

Graph object, specified as a navGraph object.

State vectors, specified as a M-by-N matrix. Each row in the matrix specify a state vector. M denotes the number of states to be added to the input graph. N denotes the length of the state vector that define a state. The state vectors must be of the same length as those defined in the states table of the input graph.

Note

If the specified state vectors already exist in the states table of the input graph, the function will not add the duplicate state vectors to the graph.

Data Types: double

Metadata containing additional information about the states, specified as a numeric array, cell array of character vectors, string array, or cell array of strings.

Data Types: double | string | cell

Output Arguments

collapse all

State identifiers, returned as a column vector of positive integers. State identifiers represent the indices of the states added to the states table of the graph. The length of the vector specifies the number of states added to the input graph.

Extended Capabilities

Version History

Introduced in R2024a