视觉画布设计
canvas-design
基于设计原则创作静态视觉作品,用于海报与品牌图形。
matlab-write-help【文档与办公】Generate or improve MATLAB help text (documentation comments) for a function, class, or script file following MathWorks standards (H1 line, syntax paragraphs, See Also, 75-char lines). Read BEFORE writing MATLAB help — default patterns (Inputs:/Outputs: lists, block comments, uppercase See Also) produce non-conforming output. Use when writing, rewrit…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Resolve $file to an M-file path and generate complete, standards-compliant MATLAB help text for it. If the file already has help text, improve it to meet the standards below. Present the proposed help text to the user for review before modifying the file.
All rules below are mandatory. Violating any of them produces non-conforming help.
Help begins on line 2 (after function or classdef line) for functions/classes
Help begins on line 1 for scripts or built-in sidecar files
Help comments must match the indentation of the body code. Look at the first non-comment content after the help block to determine the indentation level:
classdef files: the body is properties/methods blocks,
which are always indented 4 spaces → class help at 4 spacesfunction files: look at the first executable statement.
If at column 1, help at column 1; if at 4 spaces, help at 4 spaces.
Example at 4-space indent:
function result = myFunc(x)
%myFunc - Brief description
% RESULT = myFunc(X) does something with X.
result = x + 1;
end
No comment line may exceed 75 characters measured from the % onward
(i.e., 75 characters of comment content including the % itself).
If the % is indented, the total line width is indent + 75.
Syntax lines are exempt (see below).
Max column = indent + 75 (e.g., indent 12 → max col 87).
Count from the %, not from column 1.
No tabs — spaces only
No trailing whitespace
No block comments (%{ %}) — only % line comments
No hardcoded links to documentation or webpages
No 'href="matlab:' evaluation links
A blank line (no %) separates help from the copyright line.
When function or class names appear in help text (H1 lines, syntax
paragraphs, prose references, and See Also lines), they use help
casing to distinguish them from ordinary words. The help command
renders help-cased names as bold or hyperlinks.
Rules:
sort → SORT, magic → MAGIC)Table → TABLE, Handle → HANDLE)readTable → readTable, XMLReader → XMLReader,
image_resize → image_resize, pdist2 → pdist2)%FUNCNAME - Brief description without a period
% immediately followed by the function name in help
casing (no space after %)- (space-dash-space) separates the name from the description%FUNC - Brief description without a period
% B = FUNC(A,OPTION) does the thing with A using OPTION.
%
% B = FUNC(A,Name=VALUE) also specifies a name-value argument.
Note: no blank % line between the H1 and the first syntax paragraph.
One paragraph per syntax
Each paragraph begins with the syntax it describes followed by a
lowercase verb — the syntax reads as the subject of the sentence
(e.g., % B = FUNC(A) does... not % B = FUNC(A) Returns...)
Function name uses help casing
All lines indented with three spaces after % (i.e., % )
No blank % line before the first syntax paragraph
A blank % line separates each syntax paragraph
Input ordering in syntax: Required → Optional → Name-Value
The first syntax paragraph describes all required inputs only
Each optional input gets its own syntax paragraph
The first syntax paragraph shows only the primary output. Additional outputs are introduced one at a time in later syntax paragraphs — never jump from one output to all outputs at once. Each new output gets its own paragraph. This mirrors the input layering — start simple, add complexity one piece at a time. Examples:
Two outputs — one additional paragraph:
% IDX = FINDNEAREST(POINTS,TARGET) finds the nearest point.
%
% [IDX,DIST] = FINDNEAREST(...) also returns the distances.
Three outputs — two additional paragraphs (not one):
% SEGMENTS = segmentSignal(DATA,THRESHOLD) segments the signal.
%
% [SEGMENTS,BOUNDARIES] = segmentSignal(...) also returns the
% boundary indices where segments split.
%
% [SEGMENTS,BOUNDARIES,LABELS] = segmentSignal(...) also returns
% string labels for each segment.
Use ... to abbreviate previously-described arguments when an optional
applies to all prior syntaxes
If a syntax exceeds 75 characters, the syntax itself is exempt from wrapping — keep it on one line. The description text that follows wraps normally starting on the next line. To shorten long syntaxes:
[...] when outputs were described in an
earlier syntax (e.g., [...] = func(...,Name=VAL))... for previously-described inputsdata → DATA, method → METHOD, result → RESULT,
depth → DEPTH, obj → OBJ, tf → TF
but filePath → filePath, queryPoints → queryPoints,
startSample → startSample, maxMemory → maxMemory,
otherBuffer → otherBuffer
(these contain uppercase letters, so they keep exact casing)TFA, B, X)% B = SORT(A,DIRECTION) also specifies the sort direction. DIRECTION
% must be:
% "ascend" - (default) Sorts in ascending order.
% "descend" - Sorts in descending order.
% (i.e., % )- (space-dash-space)(default) at start of description% B = FUNC(A,...,Name=VALUE) also specifies the thing.
Name=VALUE with the value in UPPERCASE% Example: Brief label describing the example
% x = func(input1,input2);
% disp(x)
% line% Example: (or % Example: label)% (i.e., % )for, if, while)% line% comments to annotate code, not prose between lines%
% See also readtable, griddedInterpolant, pdist2
% line% See also (three-space indent)readtable, griddedInterpolant, pdist2)
— do NOT apply help casing to See Also namespkg.subpkg.funcName). Functions
in the SAME folder (same package level) use bare names — they
resolve relative to each otherhelp without full qualification, and even then only
from within the class. In @class folders, any file that is not the
class constructor is a method; check its Access before referencing it@class folders SHOULD have a See Also line referencing
the class itself and relevant public methods or properties of the
class, using unqualified names (e.g., ClassName, methodName,
propertyName). Do NOT reference other private methods% See also readtable, readtimetable,
% griddedInterpolant, scatteredInterpolant
%
% Note: FUNC is in the Signal Processing Toolbox
% line% Note: A copyright line is specifically a comment that matches:
% Copyright YYYY
where the line starts with % followed by spaces, then the whole word
Copyright, then a four-digit year or year range (e.g.,2024 or
2020-2025). Other comments that merely contain the word "copyright" as
part of a function name or description are NOT copyright lines.
% — just a newline)help command
stops reading at the first non-comment lineFor classdef files:
MyClass(data, opts) where data is required:
% OBJ = MyClass(DATA) creates an object from DATA.
%
% OBJ = MyClass(DATA, sampleRate) also specifies the sample rate.
% CLASSNAME functions:
% method1 - Brief description
% method2 - Brief description
%
% CLASSNAME properties:
% Prop1 - Brief description
% Prop2 - Brief description
CLASSNAME functions: — use the word
functions, NOT methods (matches MATLAB's own help output).
Never write CLASSNAME methods:@class folder), DO reference the class itself
and other public methods or properties — use unqualified names
(e.g., ClassName, methodName, propertyName)When generating help for a classdef file, always check that every public property has a comment. This is not optional and should not require the user to ask — it is part of the standard classdef help workflow. If any public property lacks a comment, add one.
Every public property should have at least a postfix comment:
Postfix (short, H1 only):
PropName % Brief description
Prefix (for longer descriptions):
%PROPNAME - Brief description
% Additional detail about the property.
PropName
If properties already have postfix comments, leave them as-is. Only add missing ones. Do not duplicate the class-level properties listing — the listing is a summary, while property-level comments are inline docs.
Methods defined locally in a classdef file (not in separate @class
folder files) follow these rules based on access level:
Public methods get full function help:
% line between the H1 and the syntax paragraph% — do not wrap short% OUT = func(A,B,C)) is exempt from
the 75-char limit — never wrap a syntax across lines. If the syntax
exceeds 75 chars, put the description on the next line function result = myMethod(obj, x)
%myMethod - Brief description
% RESULT = myMethod(OBJ,X) does something with X.
result = x + 1;
end
Protected and private methods get H1 only:
function result = helperMethod(obj)
%helperMethod - Brief description
result = obj.data;
end
Exceptions that get H1 only regardless of access:
get.Prop, set.Prop)Overriding methods and help inheritance:
When a subclass overrides a superclass method, MATLAB inherits the superclass help if the override has none. Use this to avoid duplication:
Write superclass help generically — describe what, not how.
Help for locally-defined methods is indented to match the method body
(typically 12 spaces when the function keyword is at 8 spaces).
Methods in separate files (@class folders) follow standard function
help rules independently — help indentation matches the body code
indentation of that file (column 1 if the body is at column 1, or
4 spaces if the body is indented 4 spaces).
When a function has an arguments block, read it to determine the correct
syntax paragraphs. The block tells you everything:
= default value, no dot prefix
inputData (1,:) double;
= default, no dot prefix
method (1,1) string = "linear";
opts.Tolerance (1,1) double = 1e-6;
Use this to generate syntax paragraphs:
...)Name=VALUE in additional syntaxesNever write a raw internal variable name like ARGS in a syntax — expand
it into the actual name-value pairs the caller would use.
$file to a full file path:
$file is already a valid absolute or relative path to an
existing .m file, use it directlyfoundName = which("$file");
if ~isempty(foundName), disp(foundName), end
arguments block, read it to determine
required, optional, and name-value arguments%, correct section order, correct
indentationCopyright 2026 The MathWorks, Inc.