Main Content

removeNode

Remove node from factor graph

Since R2024a

    Description

    removeNode(fg,nodeID) removes the specified node from the factor graph, removes any factors connected to that node, and removes any nodes that become disconnected from any factors in the process of node removal.

    example

    removedNodeIDs = removeNode(fg,nodeID) returns the node IDs of all the nodes removed along with the specified node ID.

    example

    [removedNodeIDs,removedFactorIDs] = removeNode(fg,nodeID) additionally returns the factor IDs of factors that were removed along with the specified nodes.

    Examples

    collapse all

    Import a factor graph with five 2-D pose nodes and then visualize the factor graph.

    fg = importFactorGraph("fiveNodeFactorGraph.g2o");
    show(fg,Legend="on");
    title("Five-Node Factor Graph")

    lim = axis; 

    Get all of the 2-D pose node IDs of the graph and remove the first node in the factor graph.

    ids = nodeIDs(fg,NodeType="POSE_SE2")
    ids = 1×5
    
         1     2     3     4     5
    
    
    [removedNodeID,removedFactorID] = removeNode(fg,ids(1))
    removedNodeID = 1
    
    removedFactorID = 0
    

    Note that removeNode removed the first node, along with the factor related to it. Show the factor graph again to visualize this change.

    show(fg);
    title("Node 0 Removed")
    axis(lim) % Use previous limits for easier comparison

    Now remove the second to last node in the factor graph.

    nodeToRemove = ids(end-1)
    nodeToRemove = 4
    
    removedNodeIDs = removeNode(fg,nodeToRemove)
    removedNodeIDs = 1×2
    
         4     5
    
    

    Note that this time, removeNode removed node 4 in addition to the node 3. This is because node 4 is only connected to node 3 in the factor graph, so removing node 3 would leave node 4 disconnected from the factor graph.

    show(fg);
    title("Node 3 and Node 4 Removed")
    axis(lim);

    Input Arguments

    collapse all

    Factor graph, specified as a factorGraph object.

    ID of the node to remove from the factor graph, specified as a nonnegative integer or an N-element row vector of nonnegative integers. N is the total number of nodes to remove.

    Output Arguments

    collapse all

    IDs of removed nodes, returned as an M-element vector of nonnegative integers. M is equal to the sum of the length of nodeID and any nodes that would become completely disconnected from any factors as a result of removing factors during the node removal process.

    IDs of removed factors, returned as a P-element vector of nonnegative integers. P is the total number of factors removed during the node removal process.

    Extended Capabilities

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

    Version History

    Introduced in R2024a