matlab-diagnose-parfor

Diagnose and fix parfor variable classification errors in MATLAB code.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

MATLAB parfor loops enforce strict variable classification rules (sliced, broadcast, reduction, temporary) that are easy to violate and hard to reason about from memory. This Skill uses MATLAB's code analyser as the authoritative classifier to pinpoint the exact error and apply a proven fix pattern, instead of guessing at classification rules.

Core Features & Use Cases

  • Analyser-driven diagnosis: Runs the MATLAB code analyser (checkcode/codeIssues via the MATLAB MCP tool) to get the exact parfor error before attempting any fix.
  • Seven fix patterns: Covers struct-field slicing, multiple sliced subscripts, invalid sliced indexing, sliced-write/full-read conflicts, non-standard reductions, temporary variable issues, and conditional updates that must survive the loop.
  • Full message catalog: A reference file maps all 48 parfor analyser message IDs (PFUNK, PFSLO, PFTUS, etc.) to root causes and fixes.
  • Use Case: A user converts a for loop to parfor and gets "Unable to classify variable 'out'". The Skill runs the analyser, identifies that struct fields cannot be sliced, and rewrites the loop to accumulate into plain arrays before packing the struct after the loop.

Quick Start

Ask the agent to diagnose why the parfor loop in your MATLAB file fails to run and fix the variable classification errors.

Frequently Asked Questions about matlab-diagnose-parfor

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

FAQPage Schema
How do I fix "Unable to classify variable" in a MATLAB parfor loop?

Run MATLAB's code analyser (checkcode or codeIssues) on the file to get the exact error, then identify the conflicting access pattern. Common causes include struct fields used as sliced outputs, indexed reductions, or mixing sliced writes with whole-variable reads, each of which has a specific restructuring fix.

How to convert a for loop to parfor in MATLAB?

Change the loop keyword to parfor, then run the code analyser to verify every variable fits exactly one classification: loop, sliced, broadcast, reduction, or temporary. Fix any reported violations, such as conditional assignments or inconsistent subscript patterns, before running.

Why can't I use struct fields as sliced variables in parfor?

Sliced variables require first-level parenthesis or brace indexing with the loop variable; dot-indexing on a struct field is never valid for slicing. Extract each field into its own array, slice those arrays in the loop, then pack the struct after the loop.

Does this skill help with parfor performance problems?

No, it targets classification errors that prevent parfor from running, not performance tuning. Slow-but-working parfor loops, pool configuration, and worker setup are explicitly out of scope.

What is a reduction variable in MATLAB parfor?

A reduction variable must appear as the whole variable in the form X = X op expr, where op is an associative operator like + or .* or a function like max or union. Indexed reductions like counts(bin) = counts(bin) + 1 are not supported and must be restructured as whole-variable reductions.

Why is my parfor temporary variable unavailable after the loop?

Temporary variables are discarded when a parfor loop ends by design. If a value conditionally computed inside the loop is needed afterward, store per-iteration results as sliced output and reduce them after the loop, for example with max.