Main Content


Search for parameter names in ROS 2 node

Since R2022b


paramNames = search(paramObj,searchStr) searches for parameter names in the ROS 2 node associated with the parameter object paramObj, which contain the string searchStr. The function returns the matching parameter names in pNames.


[paramNames,paramValues] = search(paramObj,searchStr) also returns the corresponding values pValues of the matching parameters in pNames.


collapse all

Create a ROS 2 node with parameters.

nodeParams.my_double = 2.0;
nodeParams.my_namespace.my_int = int64(1);
nodeParams.my_double_array = [1.1 2.2 3.3];
nodeParams.my_string = "Keyparams";
node1 = ros2node("/node1",Parameters=nodeParams);

Create a ros2param object to interact with the parameters of the ROS 2 node, /node1.

paramObj = ros2param("/node1");

Use the set function to change the value of the parameter my_string.


Use the get function to obtain the new value of my_string.

stringVal = get(paramObj,"my_string")
stringVal = 

Use the has function to check if the parameter my_char exists in the ROS 2 node, /node1.

flag = has(paramObj,"my_char")
flag = logical

Use the search function to search for names of all the parameters that contain the string "my_d". Obtain the values of the matching parameters.

[pNames,pVals] = search(paramObj,"my_d")
pNames = 2x1 cell
    {'my_double'      }

pVals=2×1 cell array
    {[                   2]}
    {[1.1000 2.2000 3.3000]}

Use the list function to list the names of all parameters in the ROS 2 node.

pList = list(paramObj)
pList = 5x1 cell
    {'my_double'          }
    {'my_double_array'    }
    {'my_string'          }
    {'use_sim_time'       }

Input Arguments

collapse all

ROS 2 parameter object, specified as a ros2param object handle.

ROS 2 parameter search string specified as a string scalar or character vector. The search function returns all parameters that contain this search string.

Output Arguments

collapse all

Matching parameter names, returned as a cell array of character vectors.

Values of the matching parameters, returned as a cell array.

Data Types: int64 | logical | char | string | double | cell

Version History

Introduced in R2022b

See Also