How to find the name of the file that is being edited?

조회 수: 8 (최근 30일)
Alecsander Eitan
Alecsander Eitan 2015년 9월 1일
댓글: Guillaume 2015년 9월 3일
Hi, I would like to write a Matlab script that performs an operation on the file that is being eddited (file that is displayed now in the editor window). To do so, I need to know the name of the file. I was looking all over the places and didn't find the solution. To be more specific, I looking for a solution like gcf() The reason I'm looking for such a solution is that I would like to do some analysis and processing on the eddited file like: Publish (without the Matlab option), save to... Thank you, Alecs

채택된 답변

Steven Lord
Steven Lord 2015년 9월 1일
Or you could use the Editor API. Look for help on matlab.desktop.editor for more information -- it seems like getActiveFilename is what you want.
  댓글 수: 2
Alecsander Eitan
Alecsander Eitan 2015년 9월 1일
Thank you! It works! By using: EDITOROBJ = matlab.desktop.editor.getActive; I get the name. Thank you, Alecs
Guillaume
Guillaume 2015년 9월 3일
Considering the editor API has been introduced in 2011, it would be good if its documentation was discoverable.
I certainly wasn't aware of it since a search in the help browser does not return anything useful. Even a lookfor editor does not return any hint that there's such an api.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Adam
Adam 2015년 9월 1일
편집: Adam 2015년 9월 1일
doc mfilename
will give you the name of the file currently executing.
I'm not aware of any function that will give you the names of all files currently open in the editor though if that is what you mean instead.

Guillaume
Guillaume 2015년 9월 1일
See Yair's site on how to access the editor. Accessing the name of the file being currently edited is one of the first example:
desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
jEditor = desktop.getGroupContainer('Editor').getTopLevelAncestor;
jEditor.getTitle
Of course, as it relies on undocumented interfaces, there's no guarantee that it will work in future versions.
  댓글 수: 1
Alecsander Eitan
Alecsander Eitan 2015년 9월 1일
Hi, Unfortunatly this method is not working for me on Matlab R2014a. But next answer is :-)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by