Define a class in a Livescript with the .m extension

10 ビュー (過去 30 日間)
CAME
CAME 2025 年 7 月 2 日
回答済み: Ruchika Parag 2025 年 7 月 7 日
Hello,
As of R2025a livescripts can be saved as .m files. I am wondering if it is possible to create classes in livescripts saved as .m files. This to doument them with the livescript features.
  2 件のコメント
Matt J
Matt J 2025 年 7 月 2 日
Did you try it?
CAME
CAME 2025 年 7 月 2 日

I did. It cannot be done. Matlab will throw an error.

サインインしてコメントする。

採用された回答

Ruchika Parag
Ruchika Parag 2025 年 7 月 7 日
Hi @CAME, as of MATLAB R2025a, live scripts can indeed be saved in a plain-text .m format, which makes them more compatible with version control and easier to read in text editors. However, this change does not allow class definitions (classdef) to be created directly within live scripts, even when saved with a .m extension.
Live scripts are designed primarily for narrative workflows, examples, and analysis rather than for defining reusable code structures like classes. While you can call and interact with classes defined in separate .m class files from within a live script, the script itself cannot contain the full classdef block.
To document classes using live script features such as formatted text, equations, and embedded outputs, the recommended workflow is:
  1. Define your class in a standard .m file (outside the live script).
  2. Use a live script to demonstrate and document how the class works—instantiating objects, calling methods, and explaining functionality with commentary and rich formatting.
This approach maintains compatibility with MATLAB’s class system while leveraging the documentation benefits of live scripts. Hope this helps!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeModel, Block, and Port Callbacks についてさらに検索

タグ

製品


リリース

R2025a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by