Skip to content
Latchkey

MATLAB "Error using X" runtime failure in CI

MATLAB threw a runtime error from inside a function call. The "Error using X" header names the function and the next line states the real reason: wrong type, wrong size, or an invalid value. This is a genuine code failure, not a setup issue.

What this error means

A -batch run stops with "Error using X" and a reason such as "Matrix dimensions must agree" or "Invalid argument", then a stack trace. Tests report the same as a failure.

MATLAB
Error using  *
Incorrect dimensions for matrix multiplication. Check that the number of columns
in the first matrix matches the number of rows in the second matrix.

Error in solve (line 8)
    y = A * x;

Common causes

Argument types or sizes are wrong

The values passed at runtime violate the function contract - mismatched matrix dimensions, wrong class, or an empty input.

Data differs on the runner

CI loads different fixtures or generates different inputs than your local session, exposing a shape assumption.

How to fix it

Read the reason line, not just the header

  1. Look at the line under "Error using X" - it states the exact violation.
  2. Print the sizes/classes of the inputs at the failing call.
  3. Fix the shape or type mismatch, or validate inputs with validateattributes.
analyze.m
% guard the contract so failures are explicit
validateattributes(x, {'double'}, {'vector'});

Reproduce with the CI fixtures

Run the failing function against the same data CI uses so the mismatch reproduces locally.

How to prevent it

  • Validate inputs with validateattributes at function boundaries.
  • Use the same fixtures locally and in CI.
  • Add tests that assert on input shapes and types.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →