<!--
{
  "availability" : [
    "iOS: 8.0.0 - 14.0.0",
    "iPadOS: 8.0.0 - 14.0.0",
    "macCatalyst: 13.1.0 - 14.0.0",
    "macOS: 10.10.0 - 11.0.0",
    "tvOS: 8.0.0 - 14.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 1.0.0 - 7.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/la_diagonal_matrix_from_vector(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@la_diagonal_matrix_from_vector"
  },
  "title" : "la_diagonal_matrix_from_vector(_:_:)"
}
-->

# la_diagonal_matrix_from_vector(_:_:)

```
func la_diagonal_matrix_from_vector(_ vector: la_object_t, _ matrix_diagonal: la_index_t) -> la_object_t
```

## Parameters

`vector`

Vector providing the data for the non-zero diagonal.

`matrix_diagonal`

The index of the non-zero diagonal.

## Discussion\abstract Create a matrix with a specified diagonal provided by a vector, and zeros in
all the other entries.
\discussion Creates a new matrix with entries on the specified diagonal taken from the
vector argument, and zeros in the other entries.  The matrix is square, and
has size length(vector) + abs(matrix_diagonal).

If matrix_diagonal is zero, the main diagonal is set.  If matrix_diagonal is
+1, the first superdiagonal is set.  If matrix_diagonal is -2, the second
subdiagonal is set.

The diagonal may be specified by a vector or by a matrix that has only one
row or only one column.  If the provided object is not a vector or matrix,
or is a matrix with both dimensions larger than one, the returned object
will have status LA_INVALID_PARAMETER_ERROR.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)