# Matlab Review Fi Object Code

Reviews MATLAB fixed-point (fi) code for performance, code generation efficiency, and...

- Repository: https://github.com/matlab/matlab-agentic-toolkit (1237 stars)
- Category: Engineering
- License: see repository
- Last updated: 2026-10-27
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add matlab/matlab-agentic-toolkit --skill matlab-review-fi-object-code -g -a claude-code -y`
Codex: `npx skills add matlab/matlab-agentic-toolkit --skill matlab-review-fi-object-code -g -a codex -y`
Cursor: `npx skills add matlab/matlab-agentic-toolkit --skill matlab-review-fi-object-code -g -a cursor -y`
Gemini CLI: `npx skills add matlab/matlab-agentic-toolkit --skill matlab-review-fi-object-code -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add matlab/matlab-agentic-toolkit`

## Description

Reviews MATLAB fixed-point (fi) code for performance, code generation efficiency, and correctness. Identifies antipatterns and suggests idiomatic improvements. Use when reviewing fi, fimath, numerictype, or quantizenumeric code.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# fi Best Practices Review

Reviews MATLAB code for fixed-point (`fi`) best practices and suggests improvements for performance, code generation efficiency, and correctness.

## When to Use

- Reviewing MATLAB code that uses `fi`, `fimath`, `numerictype`, or `quantizenumeric`
- Optimizing fixed-point simulation speed
- Preparing fixed-point code for C or hardware code generation

## When Not to Use

- Code using only built-in integer types (`int8`, `uint16`, etc.) without `fi`
- Pure floating-point algorithms with no fixed-point intent
- Simulink-only workflows where fixed-point is configured through block dialogs (use Fixed-Point Tool instead)

## Checklist

When reviewing code, check for ALL of the following:

### 1. Vectorize fi() Calls

**Problem**: Scalar `fi()` in a loop is slow due to per-element object construction overhead.

**Fix**: Pass entire arrays to `fi()` at once.

```matlab
% BAD, slow: per-element fi object construction
for k = 1:N
    x_fi(k) = fi(x(k), 1, 18, 16, F);
end

% GOOD, fast: single vectorized call, bit-true identical result
x_fi = fi(x, 1, 18, 16, F);
```

### 2. Separate Data Types from Algorithm

**Problem**: Hardcoding fi types inside algorithm code makes it impossible to switch between float/fixed or compare configurations.

**Fix**: Use a types table with empty prototypes and `cast(...,'like',...)`.

```matlab
% Types table (separate function)
function T = mytypes(dt)
  switch dt
    case 'double'
      T.b = double([]);  T.x = double([]);  T.y = double([]);
    case 'single'
      T.b = single([]);  T.x = single([]);  T.y = single([]);
    case 'fixed16'
      F = fimath('RoundingMethod','Floor','OverflowAction','Wrap', ...
                 'ProductMode','KeepLSB','ProductWordLength',32, ...
                 'SumMode','KeepLSB','SumWordLength',32);
      T.b = fi([], 1, 16, 15, F);
      T.x = fi([], 1, 16, 15, F);
      T.y = fi([], 1, 16, 14, F);
  end
end

The rest: https://github.com/matlab/matlab-agentic-toolkit/blob/HEAD/skills-catalog/code-generation/matlab-review-fi-object-code/SKILL.md
