Main Content

findstate

Find IDs of states

Since R2023a

    Description

    example

    stateIDS = findstate(graph,stateData) finds the state IDs stateIDS of the states specified by stateData, if they exist in the navGraph object graph.

    The function returns stateIDS when all elements of a row of stateData are identical to elements of a row in the States table.

    Examples

    collapse all

    Load navGraph data for states and links.

    load navGraphData.mat

    Create a table to use to search for the state ID.

    stateData = table([3 6 0.142170047601527; 1 1 1],["F"; "A"],[2; 2], ...
                      VariableNames={'StateVector','Name','Lanes'});

    Find the indices of the states.

    id = findstate(navGraphObj,stateData)
    id = 2×1
    
         6
         0
    
    

    The navGraph states table contains a state corresponding to the first state data, so the function returns its index. However, the states table does not contain a state that corresponds to the second state, so the function returns 0.

    navGraphObj.States
    ans=8×3 table
              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  
    
    
    stateIDS = state2index(navGraphObj,stateData.StateVector)
    stateIDS = 2×1
    
         6
         0
    
    

    Input Arguments

    collapse all

    Graph object, specified as a navGraph object.

    State data, specified as the names of the states, the state vectors, or a states table.

    Specify the names of the states as a column vector of character vectors, column vector of string scalars, or cell array of character vectors.

    Specify the state vectors as a matrix in which each row represents a state vector. The state vectors must be of the same size as those in the StateVector column of the States table.

    Specify the states table as a table that the same columns as the States table.

    Data Types: single | double | cell | char | string | table

    Output Arguments

    collapse all

    State IDs, returned as a column vector of positive integers. When the function does not find a specified state pair, the value for the corresponding element in stateIDS is 0

    Data Types: double

    Extended Capabilities

    Version History

    Introduced in R2023a