# removeFactor

Remove factor from factor graph

Since R2024a

## Syntax

``removeFactor(fg,factorID)``
``removedNodeIDs = removeFactor(fg,factorID)``

## Description

````removeFactor(fg,factorID)` removes a factor with the specified factor ID from the factor graph as well as removing any nodes related to the factor that would become disconnected from any factor in the factor graph as a result of removing the factor.```
````removedNodeIDs = removeFactor(fg,factorID)` optionally returns the IDs of any nodes that were removed along with the specified factor.```

example

## 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; `

Remove the last factor in the factor graph.

`removedNodeIDs = removeFactor(fg,fg.NumFactors-1)`
```removedNodeIDs = 5 ```

Note that `removeFactor` removed the last node with an ID of 5 along with the last factor because after `removeFactor` removes the last factor, the last node has no other factors connected to it.

Show the factor graph again to visualize this change.

```show(fg); title("Last Factor and Node 5 Removed") axis(lim)```

## Input Arguments

collapse all

Factor graph, specified as a `factorGraph` object.

ID of factor to remove, specified as a nonnegative integer or an N-element array of nonnegative integers. N is the total number of factors to remove.

## Output Arguments

collapse all

IDs of removed nodes that became disconnected after removing the specified factor, returned as an M-element vector of nonnegative integers. M is the number of nodes that would become completely disconnected as a result of removing related factors.

## Version History

Introduced in R2024a