协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
matlab-fit-curve【开发与工程】Fit curves and surfaces interactively with the Curve Fitter app for a complete no-code fitting workflow. Invoke this skill when the Curve Fitter app, cftool, curveFitter, or "curve fitting tool/app" is mentioned in any way. Also use when exploring or comparing fit types (regression, interpolation, smoothing, splines, custom equations); excluding outl…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Guides interactive curve and surface fitting through the Curve Fitter app as part of the Curve Fitting Toolbox. Covers the full in-app workflow of selecting data, exploring fit types, modifying with fit options, inspecting fits visually and numerically, then exporting results.
No-code fitting
Interactive exploration
App-specific features
.sfit) for convenience or collaborationCLI workflows (no app involvement)
fit(), fittype(), fitoptions() directly in their own scripts/functionsSpline workflows
csapi, csaps, fnbrk, etc.)splinetool or bspligui appsOther tools and domains
interp1, pchip, scatteredInterpolant, griddedInterpolant, spline, smoothdatafitlm, fitnlm, cvpartition)lsqnonlin, fmincon, lsqcurvefit, lsqlin)If CLI is the better approach, do not suggest app workflows. If neither section clearly applies, use these signals to disambiguate:
| Signal | Recommendation | Why |
|---|---|---|
| User says "compare" fits | Depends | Visual curve comparison -> CLI (overlaid on same axes). Comparing goodness of fit metrics -> App (Table of Fits). Interactive adjustment -> App. |
| User just wants to visualize a single fit | CLI | CLI plotting handles this well |
| User wants to overlay multiple fits on same axes | CLI | App shows fits in separate figures only |
| User needs to exclude outliers by visual inspection | App | Point-and-click exclusion is easier than computing indices |
| User needs formal validation data | App | The app has explicit validation data support |
User instructions always take precedence. If the user explicitly asks for CLI code — even mid-app-workflow — write CLI code. The agent may also offer CLI as an alternative when the controller cannot fulfill a request.
Do not spontaneously switch between app and CLI mid-workflow. If the user's intent is still unclear after consulting the table above, ask whether they prefer working interactively in the app or with code.
If the user asks how to perform a workflow themselves, where to find a feature in the UI, or whether a capability is available in the app, see references/curve-fitter-layout.md for the full layout and feature locations.
Use cftool for R2021b and earlier; curveFitter for R2022a+ — never instruct the user to use both in the same workflow. Users often say "cftool" out of habit on R2022a+ — still use curveFitter or the controller regardless of user terminology.
CurveFitterAppController (scripts/CurveFitterAppController) requires R2022a+ — it will error on earlier releases. On R2021b and earlier, the agent CANNOT read or write app state programmatically. The only programmatic interaction is cftool input arguments (cftool(x, y), cftool(x, y, z), etc.). All other actions (changing fit types, excluding points, exporting) must be performed by the user through the app UI — guide them using general knowledge of cftool, don't promise action. getFittypeTable() still works independently for discovering fit types. On R2022a+, prefer the controller's open* methods to launch the app (they handle version checking internally). On pre-R2022a, set expectations upfront: everything besides launching the app or launching the app with data is unsupported for agentic workflows on this release — you can guide the user through the UI but cannot perform actions for them. Offer CLI fitting as an alternative path. Don't let users discover limitations one by one.
Critical for pre-R2022a: On these releases, ALL of the following apply:
fit() code as a substitute for app actions. Do not pause and instruct users to click UI elements. Exceptions:
references/curve-fitter-layout.md first. Only offer CLI as an alternative if the feature isn't available in the app or the workflow is trending toward the ambiguous signals in "When NOT to Use"fit(), fittype(), fitoptions(), etc. for quick lookups (e.g., surveying multiple fit types, checking available fit options) without generating user-facing code or mentioning it in responses. This is distinct from generating code for the user.getFittypeTable() (scripts/getFittypeTable) to discover available fit types — do not guess or assume the availability of fit type names or prioritize custom equations when a built-in one exists. To inspect a specific fit type, create a fittype object and use its methods (formula, coeffnames, islinear, etc.) — fittype objects have no public properties. Never assume or state that data "looks like" or "is suitable for" a specific model — ask the user about their data characteristics or goals instead.references/interpreting-fit-results.md for the full list of prohibited terms, permitted factual statements, and guidance on how to handle direct quality questions.Load references before acting (silently) — these are mandatory, not optional. Load liberally — when in doubt about whether you need a reference, load it. Never narrate or mention loading references in user-facing text (see Rule 10):
references/api-reference.md before calling any controller method for the first time in a sessionreferences/interpreting-fit-results.md before reporting, comparing, or explaining fit resultsreferences/curve-fitter-layout.md before answering questions about app features, UI locations, or when the controller has no API for a requested actioncurve-fitter-layout.md covers R2022a+ (Curve Fitter) ONLY. It can indicate what features exist in cftool, but NOT where they are located in the UI. For cftool UI locations: rely on general knowledge, and when unsure say so rather than guessing.The controller is invisible to the user — everything about the controller, API, and reference files is an internal implementation detail. In user-facing responses:
references/curve-fitter-layout.mdAsk before acting on ambiguity — when a user's request is vague or underspecified (e.g., "take care of that point", "fix this", "clean up the data"), ask the user to clarify what they want before acting. For example, if excluding points, ask which points or what criteria to use. Never apply an arbitrary exclusion criterion (2σ, isoutlier, etc.) without user confirmation. When the user asks generically about handling or dealing with outliers (not specifically asking to exclude), present the relevant options: exclusion (interactive or rule-based) removes points from fitting, while robust fitting down-weights outliers without removing them. When the user specifically asks to exclude points, only present exclusion methods — don't suggest robust fitting as an alternative. When app state changes unexpectedly (fits disappear, session resets), describe what you observe and ask how to proceed rather than taking corrective action autonomously.
Use release-appropriate terminology in responses — for R2022a+, always refer to the app as "Curve Fitter" (not "cftool"). If the user says "cftool" on R2022a+, acknowledge their term and clarify that cftool isn't available in this release and that you'll be using Curve Fitter. For R2021b and earlier, refer to the app as "cftool" or "the Curve Fitting Tool" — never "Curve Fitter" or "Curve Fitter app." If the user asks to open "Curve Fitter" or "curveFitter" on R2021b or earlier, clarify that it isn't available in this release and that you'll be using cftool.
Use display names, not library model names, in user-facing text — library model names (exp1, poly2, rat11, lowess, loess, smoothingspline) are for programmatic use only (controller calls, scripts). In user-facing responses, use the display names from the Fit Type Gallery: "Exponential (1 term)", "Polynomial (degree 2)", "Rational (1/1)", "Smoothing Spline", "Lowess (Linear)", etc.
Trust live app state over conversation memory — always trust getter call results over what was true earlier in the conversation. Read state before acting on it. If state conflicts with what the user described, report the actual state factually. Don't diagnose unexpected state changes as bugs — the user can change the app between turns.
Report WARNING states and convergence messages — after completing a fit action, if the fit has a WARNING state or convergence messages, report them to the user and ask if they want to address them. Don't silently ignore, and don't automatically "fix" them. Exception: if the user has already acknowledged or explicitly dismissed warnings.
Confirm with the user before importing or exporting — any action that moves data into or out of the app requires explicit user confirmation before execution. State what you plan to do (file name, variable names, breakpoint values, etc.) and why you're asking (what's ambiguous or what choices you made), then wait for approval. Specific scenarios:
myfit.sfit at C:\Users\.... OK?").sfit file is detected, it can be loaded directly. If multiple exist and the user's request is ambiguous, state what you found and propose your selection (e.g., "There are multiple session files — is analysis.sfit the correct one?"). Do not load until confirmed.x, x2, y, y2), explain the ambiguity, propose your selection, and confirm before acting (e.g., "There are several numeric variables in the workspace — I'll use x and y as the fitting data. Is that correct?"). Do NOT launch the app or select data until confirmed.fitresult and goodness of fit as gof to the workspace. OK?")Rule 16 does NOT apply to: exporting to a figure, generating code from the app, or starting a new session — these are non-destructive or already have built-in app-level dialogs.
Fitting Workflow:
- [ ] Step 1: Select data
- [ ] Step 2: Choose a fit type
- [ ] Step 3: Choose fit options
- [ ] Step 4: Fit
- [ ] Step 5: Evaluate and visualize results
- [ ] Step 6: Iterate and compare
- [ ] Step 7: Export, save, or share results
This workflow applies per fit. Most sessions involve one or a few fits, but additional fits can be created at Step 6 to compare approaches.
cftool(...) (do not use curveFitter)curveFitter(...) (do not use cftool)Both commands share the same input argument syntax:
curveFitter() — launch the app with no data, or bring an already-open app to focuscurveFitter(x, y, z, w) — launch with data, or create a new fit in an already-open app. Provide [] to omit an argument (e.g., use (x, y, [], w) for weighted curve fitting)curveFitter('file.sfit') — load a saved session (must be a .sfit file)Note: In agentic workflows (R2022a+), use the controller's
openAppWithData()andopenSession()methods instead of callingcurveFitter(...)directly. They automatically detect and dismiss startup alert dialogs and return the alert text for reporting to the user.
Instantiate CurveFitterAppController (scripts/CurveFitterAppController) for read/write API access in agentic workflows. Only supported in R2022a and later. See references/api-reference.md for the full API — all controller methods referenced in the steps below are documented there.
Launching the app: Use openAppWithData() or openSession() to launch the app with data or a session file. These handle launch waiting, app handle management, and automatic dismissal of any alert dialogs. Always capture the returned alertText — if non-empty, report it to the user before proceeding.
Relevant controller methods:
openApp(), openAppWithData(), openSession(), closeApp()Assign fitting data from workspace variables. Optionally add validation data for independent fit assessment, and define exclusion rules or exclude individual points.
Relevant controller methods:
selectFittingXData(), selectFittingYData(), selectFittingZData(), selectFittingWData()selectFittingXDataFromTable(), selectFittingYDataFromTable(), selectFittingZDataFromTable(), selectFittingWDataFromTable()getFittingDataVariableNames(), isSurfaceFit()selectValidationXData(), selectValidationYData(), selectValidationZData()selectValidationXDataFromTable(), selectValidationYDataFromTable(), selectValidationZDataFromTable()getValidationDataVariableNames()setExclusionRule(), getExclusionRules(), clearAllExclusionRules()toggleInteractiveExclusions(), getInteractiveExclusions(), clearAllInteractiveExclusions()Choose a fit type based on the selected data. Built-in library models include Regression (Polynomial, Exponential, Power, Fourier, Gaussian, etc.), Interpolants, and Smoothing fit types. Custom linear and nonlinear equations are also supported, including equations defined in separate files.
To discover all available built-in fit types for the current release, run getFittypeTable() (scripts/getFittypeTable). Pass "curve" or "surface" to filter by dimensionality if known. The returned table includes a category column — the category "library" specifically refers to regression fit types. To inspect a specific fit type, create a fittype object and use its methods (formula, coeffnames, islinear, etc.) — fittype objects have no public properties.
Relevant controller methods:
setFittype(), getFittype()getFittypeTable() (utility script)Optional unless the user wants to adjust fit quality or behavior. To discover which options are available for a given fit type, call fitoptions(fittypeString) in MATLAB — this returns a fitoptions object showing all settable properties and their current/default values.
Relevant controller methods:
setFitOptions(), getFitOptions()If auto-fit is enabled (default), fitting occurs automatically when data or fit type changes. If manual mode is selected, explicitly execute the fit.
Relevant controller methods:
runFit()setAutoFit(), getAutoFit()After fitting, check the fit status for errors, warnings, or convergence issues. Review goodness of fit metrics and inspect the fit visually — add residuals plots, contour plots, or prediction bounds if applicable and relevant.
Relevant controller methods:
getFitState(), getFitStatusMessages()getGoodnessOfFit(), getGoodnessOfValidation()getFormula(), getCoefficientNames(), getCoefficientValues(), getCoefficientConfidenceIntervals()getResultsPanelText()getFitInformation()setResidualsPlotVisibility(), getResidualsPlotVisibility()setContourPlotVisibility(), getContourPlotVisibility()setPredictionBoundConfidenceLevel(), getPredictionBoundConfidenceLevel(), clearPredictionBounds()setFitPlotVisibility(), getFitPlotVisibility()setLegendVisibility(), getLegendVisibility()setGridVisibility(), getGridVisibility()If unsatisfied, iterate on the current fit by adjusting the fit type, options, or exclusions (repeat steps 2-5). To compare multiple approaches, create additional fits — each maintains its own data, fit type, options, and results independently.
Relevant controller methods:
createNewFit(), duplicateFit()selectFit(), renameFit(), deleteFit()getAllFitNames(), getFitName()getAllFitInformation()Export results to transition to other workflows (Simulink, CLI scripts), save the session for later use, or share it with others.
Relevant controller methods:
exportFitToWorkspace()exportToFigure()generateCode()exportToSimulinkLUT(), exportToSimulinkLUTEvenSpacing(), launchOptimizedLookupTableWizard()saveSession(), saveSessionAs()hasUnsavedChanges(), getSessionInfo()openSession(), startNewSession()duplicateFit() over createNewFit() + re-selecting data — when creating a comparison fit that uses the same data, duplicate preserves everything about the current fit: name (with "copy N" appended, incrementing), fitting data, validation data, fit type, fit options, exclusions, and visualization settings — not just the datareferences/interpreting-fit-results.md for how to present, compare, and explain metrics to usersCopyright 2026 The MathWorks, Inc.