2016-10-01 2 views
2

편집기의 여러 파일이 더러울 때 종종 main.m을 실행하는 실수를 저 지르 죠.MatLab에 모든 더티 파일을 프로그래밍 방식으로 저장하십시오.

모든 더러운 파일을 자동으로 저장하는 내 main.m의 시작 부분에 명령을 사용할 수 있으면 좋을 것입니다.

Save currently running script in Matlab

현재 활성화 파일을 저장하기위한 단서와 해답을 제공하지만, 모든 파일에 대해이 작업을 수행하는 방법은 무엇입니까?

+2

(문자열로) 여러 함수 이름으로 호출 할 수있는 당신이 여기에 "더러운"의 의미를 명확히 제시 이익을 위해 (수정되었지만 저장되지 않은 파일) 모국어가 아닌 사람 –

답변

3

com.mathworks.mlservices.MLEditorservice 개체를 사용하여 편집기에 액세스하고 더티 파일을 모두 저장할 수 있습니다. 이 기능 (의존성)의 목록을 전달하고 단지 사람들을 절약 할 수 있도록

service = com.mathworks.mlservices.MLEditorServices; 

% Get a vector of all open editors 
editors = service.getEditorApplication.getOpenEditors(); 

% For each editor, if it is dirty, save it 
for k = 0:(editors.size - 1) 
    editor = editors.get(k); 

    if editor.isDirty() 
     editor.save(); 
    end 
end 

오히려 맹목적으로 모든 파일을 저장하는 것보다, 당신은 약간이를 수정할 수 있습니다.

function saveAll(varargin) 
    % Convert all filenames to their full file paths 
    filenames = cellfun(@which, varargin, 'uniformoutput', false); 

    service = com.mathworks.mlservices.MLEditorServices; 

    % Get a vector of all open editors 
    editors = service.getEditorApplication.getOpenEditors(); 

    % For each editor, if it is dirty, save it 
    for k = 0:(editors.size - 1) 
     editor = editors.get(k); 

     % Check if the file in this editor is in our list of filenames 
     % and that it's dirty prior to saving it 
     if ismember(char(editor.getLongName()), filenames) && editor.isDirty() 
      editor.save(); 
     end 
    end 
end 

그리고이

saveAll('myfunc', 'myotherfunc') 
+0

고마워! (editors.get (k-1);은 0 기반, 즉 정상 색인 생성으로 인해 필요합니다.) 불행하게도이 해결책은 효과가 없습니다. 내 main.m 파일을 지저분 해 (그 스크립트를 포함하는) 파일을 실행하면 *** "java.lang.Exception가 발생합니다 : java.lang.RuntimeException : 디버깅 중에 main.m에 저장할 수 없습니다. 디버그를 종료하십시오. 모드를 시도하고 다시 시도하십시오. "*** –

+0

@Pi 색인 문제를 지적 해 주셔서 감사합니다. 당신이 디버그 모드에 있다고 말하면, 그 경우입니까? 디버그 모드에 있지 않을 때 실행 해 보셨습니까? – Suever

관련 문제