Contenu principal

mustBeColumn

R2026b

Validate that value is column vector

Since R2024b

Description

mustBeColumn(value) throws an error if value is not a column vector. A column vector has dimensions of n-by-1. This function does not return a value. mustBeColumn calls the iscolumn function to determine if the input is a column vector.

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

example

Examples

collapse all

Use mustBeColumn to validate that a value is a column vector.

Create a matrix and test whether it is a column vector. Because the matrix has a nonzero second dimension size, mustBeColumn throws an error.

u = ones(4,5);
mustBeColumn(u)
Value must be a column vector.

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

The DailyTotal function sums the values in an input column vector.

function r = DailyTotal(Sales)
    arguments
        Sales {mustBeColumn, 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 row vector into a column vector. Using mustBeColumn is stricter because it throws an error when the input is not a column vector.

Call the DailyTotal function with a column vector.

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

   228

Input Arguments

collapse all

Value to validate, specified as a column 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