matlab-validate-function-arguments

Write MATLAB functions with arguments blocks for input validation and conversion control.

995|122|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-validate-function-arguments
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: matlab-validate-function-arguments
Source: https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/matlab-programming/matlab-validate-function-arguments
Command: npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-validate-function-arguments

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

MATLAB's arguments blocks silently reshape sizes and convert classes instead of rejecting invalid inputs, causing subtle bugs. This Skill teaches correct validation semantics so functions actually reject bad inputs rather than silently transforming them.

Core Features & Use Cases

  • Arguments Block Patterns: Covers repeating arguments, name-value arguments, output validation, and composition rules across multiple blocks.
  • Migration Guidance: Maps inputParser and validateattributes patterns to modern arguments block equivalents with strict-fidelity decision tables.
  • Pitfall Prevention: Documents critical misconceptions like size specs reshaping inputs, class specs converting types, and complex values passing numeric validators.
  • Use Case: When migrating a legacy function from inputParser to an arguments block, use this Skill to choose between class specs and mustBeA validators so the new signature rejects the same inputs the original did.

Quick Start

Ask your AI agent to rewrite a MATLAB function using an arguments block that rejects column vectors and non-double inputs without silent conversion.

Frequently Asked Questions about matlab-validate-function-arguments

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate function inputs in MATLAB with arguments blocks?

Declare each input with an optional size spec, class spec, and validator functions inside an arguments block. Use validators like mustBeNumeric or mustBeA to reject invalid types, since class specs alone silently convert inputs instead of rejecting them.

How do I migrate from inputParser to arguments blocks in MATLAB?

Map addRequired to positional arguments, addOptional to arguments with defaults, and addParameter to name-value struct fields. Replace anonymous validators with built-in equivalents like mustBePositive or mustBeMember, and use mustBeA instead of class specs when the original code rejected types.

Why does my MATLAB arguments block accept column vectors when I declared (1,:)?

Size specs reshape inputs rather than reject them, so a column vector passed to (1,:) is silently transposed to a row. To actually reject column vectors, use the mustBeRow validator (R2024b or later) without a size spec.

Does the double class spec in an arguments block reject char input?

No, class specs convert rather than reject, so char input like 'hello' becomes ASCII codes before validators run. Use mustBeA(x, "double") or mustBeNumeric without a class spec to reject non-double input.

When should I not use arguments blocks in MATLAB?

Avoid arguments blocks for conditional parameters, runtime-computed validation rules, partial parsing with KeepUnmatched, and nested functions where they are unsupported. Also do not use them inside .mlx Live Scripts or .mlapp App Designer files, which are binary containers.