Main Content

state2index

Find indices for queried state vectors

Since R2023a

    Description

    example

    stateIDS = state2index(graph,states) finds the state indices stateIDS for the queried state vectors states, if they exist in the navGraph object graph.

    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 vectors, specified 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 in the navGraph object graph.

    Data Types: single | double

    Output Arguments

    collapse all

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

    Data Types: double

    Extended Capabilities

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    Version History

    Introduced in R2023a