Main Content

mustBeRow

Validate that value is row vector

Since R2024b

Description

mustBeRow(value) throws an error if value is not a row vector. A row vector has dimensions of 1-by-n. This function does not return a value.

mustBeRow calls the following function to determine if the input is a row vector:

Class support: All numeric classes, logical, and MATLAB® classes that overload isrow.

example

Examples

collapse all

Use mustBeRow to validate that a value is a row vector.

Create a matrix and test whether it is a row vector. Because the matrix has a nonzero first dimension size, mustBeRow throws an error.

u = ones(4,5);
mustBeRow(u)
Value must be a row vector.

Use an arguments block to restrict the function input to a numeric row vector using mustBeRow and mustBeNumeric.

The DailyTotal function sums the values in an input row vector. If the input is empty ([]), the sum is returned as zero.

function r = DailyTotal(Sales)
    arguments
        Sales {mustBeRow, mustBeNumeric}
    end
    if isempty(Sales)
        r = 0;
    else
        r = sum(Sales);
    end
end

An alternative way to validate the inputs is with the arguments block

arguments
    Sales (1,:) {mustBeNumeric}
end

However, the use of (1,:) leads to automatic conversion of an input column vector into a row vector. Using mustBeRow is stricter because it throws an error when the input is not a row vector.

Call the DailyTotal function with a row vector.

w = [35 42 33 70 25 23];
r = DailyTotal(w)
r =

   228

Input Arguments

collapse all

Value to validate, specified as a row vector.

Extended Capabilities

Version History

Introduced in R2024b