findstate
Description
Examples
Find Indices of States in navGraph
Object
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
graph
— Graph object
navGraph
object
Graph object, specified as a navGraph
object.
stateData
— State data
column vector of character vectors | column vector of string scalars | cell array of character vectors | matrix | table
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
stateIDS
— State IDs
column vector of positive integers
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
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2023a
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)