Documentation/Calc Functions/MUNIT

    From The Document Foundation Wiki
    Other languages:


    Function name:

    MUNIT

    Category:

    Array

    Summary:

    Creates an identity matrix of a specified size.

    An identity matrix, also sometimes called a unit matrix, is a square matrix in which all elements are set to zero, except on the main diagonal where all elements are set to one.

    Syntax:

    MUNIT(Dimensions)

    Returns:

    Returns a square array of numbers, with each cell containing either 0 or 1 depending on the position of the cell within the array. The height and width of the array are specified in the function call.

    Arguments:

    Dimensions is a positive integer value, or a reference to a cell containing that value, that is the size (height and width) of the identity matrix to be created.

    • If Dimensions is non-numeric, then MUNIT reports a #VALUE! error.
    • If Dimensions is a non-integer value, then MUNIT truncates it to an integer.
    • If Dimensions is less than 1, then MUNIT reports an invalid argument error (Err:502).

    Additional details:

    General information about Calc's array functions

    Note pin.svg

    Note:
    For convenience, the information in this subsection is repeated on all pages describing Calc's array functions.

    To avoid repetition within the subsequent text, only Windows/Linux key combinations are specified. The following table shows the mapping between these key combinations and their macOS equivalents.

    Mapping between relevant Windows/Linux and macOS key combinations
    Windows/Linux key combination macOS equivalent Comments
    Ctrl + ⇧ Shift + ↵ Enter ⌘ Cmd + ⇧ Shift + ↵ Enter Create an array formula.
    Ctrl + / ⌘ Cmd + / Select all cells in an array formula range. "/" is the division key on the numeric keypad.
    Ctrl + C ⌘ Cmd + C Copy.
    Ctrl + V ⌘ Cmd + V Paste.
    • An array is a rectangular range of cells containing data. For example, a square range of three rows by three columns is a 3 x 3 array. The smallest possible array is a 1 x 2 or 2 x 1 array, with two adjacent cells.
    • A formula in which the individual values in a cell range are evaluated is referred to as an array formula. The difference between an array formula and other formulas is that the array formula deals with several values simultaneously instead of just one.
    • If you create an array formula using the Function Wizard, you must mark the Array check box so that the results are returned in an array. Otherwise, only the value in the upper-left cell of the array being calculated is returned.
    • If you enter the array formula directly into the cell, you must use the key combination Ctrl + ⇧ Shift + ↵ Enter instead of just the ↵ Enter key. Only then does the formula become an array formula.
    • An array formula is displayed inside curly brackets or braces ("{" and "}"). It is not possible to create an array formula by manually entering these braces.
    • Some array functions take parameters that are forced to evaluate as an array formula, even when the formula is entered normally. These are MDETERM, MINVERSE, MMULT, SUMPRODUCT, SUMX2MY2, SUMX2PY2, and SUMXMY2.
    • Calc supports constant inline arrays in formulas. An inline array is enclosed within curly brackets or braces ("{" and "}"). Individual elements can be numbers (including negatives), logical constants (TRUE, FALSE), or literal strings. Non-constant expressions are not allowed. Arrays can be entered with one or more rows, and one or more columns. All rows must comprise the same number of elements; similarly, all columns must comprise the same number of elements.
    • Editing array formulas. Select the cell range containing the array formula. To select the whole range, position the cursor inside the range and press Ctrl + /. Then press F2 or position the cursor in the Input line, edit the formula as required, and use the key combination Ctrl + ⇧ Shift + ↵ Enter.
    • Deleting array formulas. Select the cell range containing the array formula. To select the whole range, position the cursor inside the range and press Ctrl + /. Press Delete to delete the array contents, including the array formula. Alternatively, press ← Backspace to bring up the Delete Contents dialog box, select Formulas or Delete all, and click OK.
    • Copying array formulas. Select the cell range containing the array formula. To select the whole range, position the cursor inside the range and press Ctrl + /. Then press F2 or position the cursor in the Input line. Copy the formula by pressing Ctrl + C. Select a range of cells where you want to insert the array formula and either press F2 or position the cursor in the Input line. Paste the formula by pressing Ctrl + V in the selected space and confirm it using the key combination Ctrl + ⇧ Shift + ↵ Enter. The selected range now contains the array formula.
    • Adjusting an array range. Select the cell range containing the array formula. To select the whole range, position the cursor inside the range and press Ctrl + /. Below the selection, to the right, you will see a small icon with which you can zoom in or out on the range using your mouse. When you adjust the array range, the array formula will not be adjusted automatically - you are only changing the range in which the results will appear.

    Examples:

    Formula Description Returns
    {=MUNIT(2)} entered as an array formula after selecting cell A1. Here the function returns the 2 x 2 identity matrix, populating cells A1:B2 with the values {1, 0; 0, 1}. See Description
    {=MUNIT(D6)} entered as an array formula after selecting cell A1. D6 contains the value 3.846. Here value of the argument is truncated to 3 and the function returns the 3 x 3 identity matrix, populating cells A1:C3 with the values {1, 0, 0; 0, 1, 0; 0, 0, 1}. See Description

    Related LibreOffice functions:

    MDETERM

    MINVERSE

    MMULT

    TRANSPOSE

    ODF standard:

    Section 6.5.5, part 2

    Related (or similar) Excel functions:

    MUNIT since v.2013.