Contenu principal

mustBeRow

R2026b

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 isrow function to determine if the input is a row vector.

Class support: All numeric classes, logical, and MATLAB® classes that implement 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.

function r = DailyTotal(Sales)
    arguments
        Sales {mustBeRow, mustBeNumeric}
    end
    r = sum(Sales);
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.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | categorical | datetime | duration | calendarDuration
Complex Number Support: Yes

Extended Capabilities

expand all

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

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced in R2024b

expand all