Communitygithub.com

matlab

建立、檢閱、遷移並安全規劃 MATLAB 或 GNU Octave 數值工作流程,包括陣列、表格/時間數據、測試、專案、圖形、MAT 檔案及明確的 Python 互通性。

matlab 是什麼?

此技能專為設計或檢閱數值程式碼、遷移 MATLAB 版本、準備可重現專案以及規劃可信賴的執行環境而設計。它明確區分 MATLAB(專有軟體,需特定授權與工具箱)與 GNU Octave(GPLv3+ 自由軟體),並要求使用者先確認執行環境、版本與授權狀態,避免假設特定產品可用。技能的核心是嚴格的安全邊界:絕不執行未經審查的 .m、.mlx、MEX 二進位檔、MAT 檔案或專案啟動/關閉動作;靜態審查無法保證安全。它列出多種需警惕的執行或程式碼載入表面,如 eval、system、Python 整合等,並強制要求先審查、隔離、取得明確同意後,才能在使用者確認的環境中執行。此技能支援所有主流 AI 代理平台(如 Claude Code、Cursor、Codex),並提供多個無網路、無執行功能的 Python CLI 輔助工具,用於批次命令規劃、原始碼掃描、專案清單驗證、MAT 檔案檢查、Python 相容性檢查、可重現性報告與函數框架生成。工作流程涵蓋從釐清目標、靜態盤點、選擇程式碼形式、明確語意、無隱藏狀態測試到執行規劃與來源追溯的完整步驟,並包含詳細的語言與數據檢查清單(腳本/函數/即時腳本、陣列/索引/數值、表格/時間表/遺漏值)以及圖形、MAT 檔案交換、專案與測試、Python 整合(以 R2026a 為準)等專題說明。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/skills/matlab

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

MATLAB 與 GNU Octave

使用此技能來設計或審查數值程式碼、遷移 MATLAB 版本、 準備可重現的專案,並規劃可信賴的執行。MATLAB 和 GNU Octave 是不同的產品:相容性只是部分,並非授權或行為的保證。

產品與授權閘門

  • MATLAB R2026a 是專有軟體。 不要假設 MATLAB、MATLAB Online、 已命名的工具箱、MATLAB Test、MATLAB Compiler、MATLAB Coder、Parallel Computing Toolbox 或附加元件已安裝、獲得授權或可供使用者使用。
  • MATLAB Runtime 不是 MATLAB。 它執行使用 MATLAB Compiler 產生的相容應用程式; 它無法執行任意原始碼或託管用於 Python 的 MATLAB Engine。 建置成品需要使用適用的授權編譯器以及 原始碼所使用的每個產品。
  • GNU Octave 11.3.0 是 GPLv3+ 下的自由軟體。 Octave 套件不是 MATLAB 工具箱。相似的名稱並不表示 API、數值、圖形或 授權等效。
  • 詢問使用者實際擁有的執行環境、版本、平台、已安裝產品和授權 情境。在確認之前,將可用性視為 unknown。

請參閱 Octave 相容性 和 執行/產品邊界。

不可協商的安全邊界

絕不執行未經審查的 .m、.mlx、MEX 二進位檔、MAT 檔案、專案啟動或 關閉動作、套件安裝程式或產生成品。靜態審查無法保證安全。

將以下視為執行或程式碼載入表面:

  • eval、evalin、assignin、文字衍生的 feval、str2func、回呼、 計時器、應用程式回呼以及動態修改的路徑;
  • system、unix、dos、shell 逸脫 !、Java、.NET、Python(py.*、 pyrun、pyrunfile)、MEX 和原生函式庫;
  • mex、codegen、MATLAB Compiler、建置任務、套件/專案啟動以及 生成的程式碼;
  • load、物件反序列化(loadobj、自訂序列化)、函數 控制代碼、Java/System 物件以及可從 MAT 檔案觸及的類別程式碼。

.mlx 對此工具組而言是 opaque 的歸檔,而 MEX 是原生可執行碼。 請勿使用 Python pickle 進行交換。首先審查,適當時隔離, 取得明確批准,然後呼叫使用者確認的可執行檔和授權。 隨附的腳本是靜態或乾執行工具:沒有任何一個會啟動 MATLAB、Octave、 Python Engine、編譯器或子程序。

預設工作流程

  1. 釐清目標。 記錄 MATLAB 版本或 Octave 版本、作業系統/架構、 基礎產品與所需工具箱/套件、預期的輸入/輸出、 數值容差,以及執行是否已授權。
  2. 靜態盤點。 在任何執行階段載入之前,掃描 .m 檔案、opaque 成品、 專案路徑、所需產品和 MAT 標頭。
  3. 選擇程式碼形式。 對於自動化,偏好使用帶有 arguments 區塊的函數。 僅將腳本用於受控編排,並將即時腳本用於 經審查的互動式敘述。
  4. 明確語意。 記錄形狀、類別、單位、遺漏值 規則、索引、隱含展開、RNG 演算法/種子、容差以及 輸出格式。
  5. 在沒有隱藏狀態的情況下測試。 保持測試固定、路徑為專案本地端、 圖形確定性,以及測試獨立於基礎工作區殘留物。
  6. 規劃執行。 產生 argv 計畫,審查啟動/路徑影響和 授權,並且僅在這些輔助工具外部獲得明確批准後才啟動。
  7. 擷取出處。 對命名輸入/程式碼進行雜湊處理,並記錄版本、產品、 RNG 策略、容差和命令計畫,而不傾倒環境。

語言與數據檢查清單

腳本、函數與即時腳本

  • 腳本共用呼叫端/基礎工作區,並留下變數。 函數具有本地工作區和明確的輸入/輸出。
  • 即時腳本(.mlx)混合了程式碼和豐富的輸出,但不是純文字 審查成品。將審查過的程式碼匯出為 .m 以進行靜態檢查。
  • 避免 clear all、廣泛的 addpath(genpath(...))、依賴 pwd、全域 變數,以及無提示的名稱遮蔽。使用專案根目錄和 fullfile。
  • 在 arguments 區塊中驗證大小、類別和值。請記住,型別 宣告可以轉換輸入;驗證器檢查但不轉換。
  • 主函數檔案應與主函數名稱匹配。本地函數 對檔案而言是私有的;自 R2024a 起,它們可以出現在腳本中的任何位置, 條件區域之外。
function y = scaleSignal(x, options)
arguments
    x (:,1) double {mustBeFinite}
    options.Scale (1,1) double {mustBeFinite, mustBeNonzero} = 1
end
y = x .* options.Scale;
end

閱讀 程式設計。

陣列、索引與數值

  • MATLAB 使用基於 1、列主索引。A(i,j)、A(k)、A(:,j)、 A{...} 和 A.(name) 具有不同的語意。
  • *、/、\ 和 ^ 是矩陣運算;帶點的形式是 逐元素的。使用 A\b,而不是 inv(A)*b。
  • 自 R2016b 起,相容維度會隱含擴展。在可能意外形成外部結果的 運算之前,斷言預期的形狀。
  • 當輸出大小已知時預先配置,但不要為了巨大的 暫存器或難以閱讀的程式碼而向量化。使用 timeit 或分析器進行測量。
  • 使用領域選擇的絕對和相對容差來比較浮點數結果, 而不是 blanket == 或 eps 的魔術倍數。
  • 固定隨機演算法和種子。使用具名的 RandStream 子串流進行 獨立的並行工作;不要將基於時間的 rng("shuffle") 用於 可重現性聲明。

閱讀 陣列 和 數學。

表格、時間表與遺漏值

  • table 具有具名的、等高的變數,這些變數可能具有不同的型別。 T(rows,vars) 返回一個 table;T{rows,vars} 提取內容;T.Var 選擇一個變數。
  • timetable 另外具有列時間。排序、驗證時區和 唯一性,然後有意地使用 retime/synchronize。
  • 遺漏哨兵是特定於型別的:NaN、NaT、<missing>、 <undefined> 和空字元向量。整數和邏輯陣列具有 無標準的遺漏哨兵。
  • 對於生產數據,定義匯入選項,而不是依賴推斷。 保留單位、時區、變數名稱、編碼和遺漏規則。

閱讀 數據匯入/匯出。

圖形與匯出

使用明確的圖形/座標軸控制代碼和 tiledlayout;標記單位;有意地設定限制、 色階、字型大小和色圖。對於出版輸出,偏好使用 exportgraphics 而非 saveas。在 R2026a 中,它匯出點陣圖、PDF/EPS/EMF、SVG、 GIF 和互動式 HTML;格式能力不同。對於合適的 PDF/SVG 風格輸出, 指定 ContentType="vector",對於點陣圖輸出,指定 Resolution。 審查無障礙性和嵌入點陣圖行為。

閱讀 圖形與匯出。

MAT 檔案與交換

  • 版本 7 是正常 save 的預設值;matfile 預設建立 7.3。 版本 4/6/7/7.3 在型別、壓縮和每個變數限制上有所不同。
  • 版本 7.3 基於 HDF5,但不是任意的 HDF5 交換合約。 部分存取和分塊可以幫助處理大型陣列。
  • 絕不載入未經審查的 MAT 檔案。首先列出標頭/數據集。物件 可以呼叫類別反序列化行為;opaque/函數/原生內容 需要升級。
  • 對於簡單交換,偏好使用帶有記錄架構的 CSV/JSON/Parquet/HDF5。 不要將 pickle 有效負載重新命名為 MAT 檔案,也不要反序列化 pickle。

閱讀 數據匯入/匯出。

專案、分析與測試

  • 使用 MATLAB Projects 來控制路徑、啟動/關閉任務、 相依性、原始碼控制以及可重現的進入點。在開啟未經審查的專案之前, 審查專案動作。
  • matlab.codetools.requiredFilesAndProducts 和 Dependency Analyzer 是 靜態近似值;動態分派可能導致遺漏或誤報。 所需產品報告並不證明授權可用。
  • 在遷移之前使用 Code Analyzer(codeIssues;舊版文字工作流程可以使用 checkcode) 和 codeCompatibilityReport。
  • 基礎 MATLAB 包括腳本、函數和基於類別的 matlab.unittest 工作流程。並行執行需要 Parallel Computing Toolbox。基於相依性的選擇、更豐富的品質儀表板、生成的 測試以及進階的覆蓋率/等效性功能可能需要 MATLAB Test 或 其他產品。
  • R2026a runtests 在目標測試屬於尚未開啟的專案時, 會自動開啟並稍後關閉該專案。在使用此行為之前, 考慮啟動和關閉動作。

閱讀 程式設計 和 執行/測試。

Python 整合,以 R2026a 為準

  • R2026a 支援 64 位元 CPython 3.9-3.13,適用於 MATLAB Interface to Python、 MATLAB Engine for Python 和 MATLAB Compiler SDK for Python。
  • 此處審查的目前 R2026a PyPI 套件是 matlabengine==26.1.12(發佈於 2026-05-08)。它需要已安裝的 R2026a;僅 MATLAB Runtime 是不夠的。R2026a 也在一個名為 matlabroot 的路徑下 提供預先安裝的 Engine 發行版。
  • 套件安裝不授予 MATLAB 或工具箱授權。配置 一個命名的直譯器/可執行檔;不要列印完整的環境、 PATH、PYTHONPATH 或憑證。
  • pyenv 控制 MATLAB 到 Python 直譯器的選擇。進程內 Python 通常需要重新啟動 MATLAB 才能切換;進程外 Python 可以 終止並重新配置。
  • 啟動 Engine 是一個明確的執行動作: matlab.engine.start_matlab() 啟動一個 MATLAB 進程,並可能簽出 一個授權。永遠不要僅僅為了探查可用性而呼叫它。
  • 驗證 NumPy 陣列、pandas DataFrames、 tables/timetables、字串/遺漏值、datetime/duration、字典、 形狀/順序以及不支援的稀疏/物件/分類案例的轉換語意。

閱讀 Python 整合。

本地輔助 CLI

每個輔助工具都是無網路、有界限、拒絕符號連結且非執行性的。 使用 Python 3.11+ 從此技能目錄執行。僅允許 Bash 來叫用這些 Python CLI 和驗證命令;切勿使用它來執行生成的 MATLAB/Octave argv 計畫或未經審查的成品。

輔助工具用途
scripts/plan_batch_command.py產生審查過的 MATLAB/Octave argv;絕不執行
scripts/scan_m_code.py掃描 .m 文字並標記 opaque .mlx/MEX 風險
scripts/validate_project_manifest.py驗證路徑和宣告的產品/授權狀態
scripts/inventory_mat_file.py標頭/元數據清單;永遠不要呼叫 loadmat
scripts/plan_python_compatibility.py檢查 R2026a CPython/Engine 相容性
scripts/reproducibility_report.py對命名本地成品進行雜湊處理並輸出有界限的報告
scripts/generate_function_scaffold.py乾執行或建立函數和單元測試框架
python scripts/scan_m_code.py path/to/source --root path/to/project
python scripts/plan_batch_command.py matlab script path/to/main.m --root path/to/project
python scripts/validate_project_manifest.py project-manifest.json --root path/to/project
python scripts/inventory_mat_file.py data.mat --root path/to/project
python scripts/plan_python_compatibility.py --python-version 3.13
python scripts/reproducibility_report.py --root path/to/project --file src/analyze.m
python scripts/generate_function_scaffold.py analyzeSignal --root path/to/project

框架生成器預設為乾執行;寫入需要 --write 並且 拒絕衝突。SciPy 和 h5py 是選用的清單後端;如果 被授權,將確切的審查版本新增到呼叫者的專案鎖定檔。 它們不是 --help 或僅標頭清單所需的,並且此技能 不執行套件安裝。

參考資料

隨附的 JSON 資產是專案清單、 可重現性清單和 R2026a Python 表格。沒有 templates/ 目錄,也沒有從 assets/ 載入 Markdown 檔案; 本地連結測試強制執行此套件合約。

主要來源(驗證日期 2026-07-23)

引用 Scientific Agent Skills

此技能是 K-Dense 的 Scientific Agent Skills 的一部分。如果它對 手稿、報告、簡報或程式碼發佈有實質貢獻,請將論文加入參考文獻或 軟體部分,並告知使用者您已這樣做:

Kassis, T., Agarw

…

[為翻譯而截斷]

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

adaptyv

How to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.

aeon

This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.

alphagenome

Look up precomputed AlphaGenome Atlas effects for any GRCh38 single-nucleotide variant (AVI score with Phred and 18 SHAP feature attributions, plus raw and quantile scores for RNA-seq, DNase, ATAC, ChIP-TF, ChIP-histone, CAGE, PRO-cap, splicing, polyadenylation and contact-map tracks), score variants or scan windows on demand with the AlphaGenome model for human and mouse (variant scoring, in silico mutagenesis, REF-versus-ALT track prediction), and build Atlas website deep links. Use when the user mentions AlphaGenome, AlphaGenome Atlas, AVI or AlphaGenome Variant Impact, DeepMind variant effect prediction, or wants to prioritise or mechanistically interpret non-coding, regulatory, splicing, enhancer, promoter, or chromatin-accessibility effects of SNVs from a VCF, credible set, or region. Research use only; not a clinical tool.

analytical-method-validation

Plan, execute, and document validation, verification, and transfer of analytical procedures under the governing framework - ICH Q2(R2) and Q14, USP <1220>/<1225>/<1226>, ICH M10 bioanalytical, CLSI EP, or ISO/IEC 17025. Use for HPLC, LC-MS/MS, GC, CE, ICP-MS, dissolution, qNMR, qPCR, NIR, and ligand binding or cell-based assays whenever the question is whether a procedure is fit for its intended purpose. Triggers include

anndata

Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.

arbor

Autonomously improve a real artifact (code, training recipe, agent harness, data pipeline, prompt) against an objective and an evaluator, using Hypothesis Tree Refinement (HTR) from the Arbor paper. Use this whenever someone wants to iteratively optimize something over many experiments without overfitting — e.g.

arboreto

Infer gene regulatory networks (GRNs) from gene expression data using scalable algorithms (GRNBoost2, GENIE3). Use when analyzing transcriptomics data (bulk RNA-seq, single-cell RNA-seq) to identify transcription factor-target gene relationships and regulatory interactions. Supports distributed computation for large-scale datasets.

astropy

Core Python library for astronomy and astrophysics workflows that need Astropy APIs, including units/quantities, coordinates, FITS I/O, tables, time systems, WCS, and cosmology. Use when implementing or debugging astronomical data analysis code with Astropy.

autoskill

Observe the user

benchling-integration

Benchling Python SDK and REST API integration for registry entities, inventory, ELN entries, workflows, Benchling Apps, and Data Warehouse queries. Use when automating lab data with benchling-sdk or the v2 API.

bgpt-paper-search

Search scientific papers and retrieve structured experimental data extracted from full-text studies via the BGPT MCP server. Returns 25+ fields per paper including methods, results, sample sizes, quality scores, and conclusions. Use for literature reviews, evidence synthesis, and finding experimental details not available in abstracts alone.

bids

>

biopython

Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.

bioservices

Unified Python interface to 40+ bioinformatics services. Use when querying multiple databases (UniProt, KEGG, ChEMBL, Reactome) in a single workflow with consistent API. Best for cross-database analysis, ID mapping across services. For quick single-database lookups use gget; for sequence/file manipulation use biopython.

bulk-rnaseq

End-to-end bulk RNA-seq orchestrator — takes raw FASTQ reads through QC and trimming (FastQC, fastp/Trim Galore), alignment and quantification (STAR, Salmon, featureCounts), assembles a gene-level counts matrix, then hands off to differential expression (pydeseq2), pathway/GSEA enrichment (pathway-enrichment), and publication figures (scientific-visualization). Use whenever the user has bulk RNA-seq reads or quant output and wants a complete, reproducible differential-expression workflow — e.g.

cellxgene-census

Query the CZ CELLxGENE Census programmatically for versioned public single-cell and spatial transcriptomics data. Use when you need population-scale cell metadata, gene expression slices, Census summary counts, source H5AD URIs/downloads, embeddings, spatial Census data, or reference atlas comparisons across organisms, tissues, diseases, assays, and cell types. For analyzing your own local single-cell data use scanpy, anndata, or scvi-tools.

cirq

Google quantum computing framework. Use when targeting Google Quantum AI hardware, designing noise-aware circuits, or running quantum characterization experiments. Best for Google hardware, noise modeling, and low-level circuit design. For IBM hardware use qiskit; for quantum ML with autodiff use pennylane; for physics simulations use qutip.

citation-management

Comprehensive citation management for academic research. Search OpenAlex, PubMed, and Google Scholar for papers, extract accurate metadata, validate citations, and generate properly formatted BibTeX entries. This skill should be used when you need to find papers, verify citation information, convert DOIs to BibTeX, or ensure reference accuracy in scientific writing.

clinical-decision-support

Prepare and validate research-only clinical decision-support evaluation, evidence-profile, cohort, survival, biomarker/model, privacy, and governance artifacts. Use for aggregate or synthetic research documentation and traceability—not patient care or live clinical operation.

clinical-reports

Create safety-bounded draft structures and run local deterministic checks for clinical case, diagnostic, trial, safety, and aggregate research reports. Use only with synthetic, de-identified, or aggregate inputs and verified source-fact manifests; every output requires qualified review.

相關技能