How to open .m fiile in editor and move to specific line number?

18 ビュー (過去 30 日間)
raym
raym 2019 年 8 月 15 日
編集済み: Adam Danz 2019 年 8 月 31 日
I'm wondering if there is a command to open a .m file and also locate to specific line?
The effect should be same with Matlab "Compare" to comparing two m files: when clicking the line numbers, the file opened and located to that line.

採用された回答

Adam Danz
Adam Danz 2019 年 8 月 15 日
編集済み: Adam Danz 2019 年 8 月 31 日
openAndGoToLine()
Input 1 is a string identifying the absolute path to the file.
Input 2 is an integer indicating the line number to go to.
matlab.desktop.editor.openAndGoToLine(file, lineNum);
Example: Open the fit() function to line 20
matlab.desktop.editor.openAndGoToLine(which('fit.m'), 20);
[Addendum]
Here's a fancy way of creating a link in the command window that will take you to the file and line number when clicked.
file = 'fit.m';
line = 20;
hotlinkcode = sprintf('Go to <a href="matlab: matlab.desktop.editor.openAndGoToLine(which(''%s''), %d) ">%s line %d</a>', file, line, file, line);
disp(hotlinkcode)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Report Generator についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by