Link to section in another live script?

30 ビュー (過去 30 日間)
Yannick Ongena
Yannick Ongena 2020 年 5 月 16 日
回答済み: Julie Shapiro 2025 年 7 月 10 日
I'm creating different live script that act as documentation of my project.
I would like to create links between those scripts so I don't have repeat things. Is this possible?
When I create a hyperlink I only seem to have the option to select a section in the current live script or an external web page...

採用された回答

Walter Roberson
Walter Roberson 2020 年 5 月 16 日
編集済み: Walter Roberson 2020 年 5 月 16 日
Here is a cheat:
function open_local_mlx(mlxname, lineNum)
whence = mfilename('fullpath');
[filedir, basename] = fileparts(whence);
mlxname = fullfile(filedir, [mlxname '.mlx']);
matlab.desktop.editor.openAndGoToLine(mlxname, lineNum);
end
This must be put into the same directory that the target .mlx file is in, and this must be a .m (not a .mlx)
Now, in the .mlx that is to contain the link, insert a hyperlink that has a target
matlab:open_local_mlx('NAMEOFMLX', LINENUMBER)
where NAMEOFMLX should be just the basic name without extension, and LINENUMBER should be the absolute line number as given by the Live Script editor. This would have to be a non-markup line -- not a section break or text area or equation. But it can be a comment line.
It is also possible to go to a particular position within a particular line, using some deeper techniques.
I would not be surprised if there is a way to search for some particular text, but I have not happened to see that yet.
  1 件のコメント
Yannick Ongena
Yannick Ongena 2020 年 5 月 16 日
Thx! Works like a charm!

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

その他の回答 (1 件)

Julie Shapiro
Julie Shapiro 2025 年 7 月 10 日
Starting in R2022a, you can link to a section in a separate, existing live script or function using the Insert Hyperlink dialog box in the Live Editor. To insert a hyperlink to a separate document, in the Insert Hyperlink dialog box, set the "Link to" field to Location in existing document and enter or browse for the file path. Then, select a location in the document preview that displays on the right.
For more information about inserting hyperlinks, see Format Text in the Live Editor.

カテゴリ

Help Center および File ExchangeLive Scripts and Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by