Saving all tabs into a folder

조회 수: 10 (최근 30일)
FFFLP
FFFLP 2023년 4월 22일
댓글: FFFLP 2023년 4월 22일
This question is about the interface. I would like to save all my Matlab script tabs into a folder. Is there any quick way to do that? Unfortunately, I cannot save them one by one since I do have 100+ scripts.
Thanks.
  댓글 수: 4
Rik
Rik 2023년 4월 22일
Are you using the words script and function interchangeably? Because 100+ scripts is very likely to be a sign of terrible design. You should use functions to make sure you have a stable interface that you can document and can improve in isolation.
FFFLP
FFFLP 2023년 4월 22일
No, I've been coding for some time (about 6 years) and I just shrink tabs as I need those time to time, instead of closing. I'm not an expert neither as you can guess. I should have used more functions though, thats true.

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

채택된 답변

Walter Roberson
Walter Roberson 2023년 4월 22일
targetdir = 'DirectoryToSaveInto';
if ~isdir(targetdir); mkdir(targetdir); end
X = matlab.desktop.editor.getAll;
newnames = fullfile(targetdir, {X.Filename}.');
arrayfun(@(Info, NewName) Info.saveAS(NewName), X, newnames)
You might need to 'Uniform', 0. You might possibly need to loop. And you might possibly need to deal specially with untitled
  댓글 수: 1
FFFLP
FFFLP 2023년 4월 22일
Thats great! I cannot thank you enough. Here's the syntax corrected running version for people need it.
targetdir = 'DirectoryToSaveInto';
if ~isdir(targetdir); mkdir(targetdir); end
X = matlab.desktop.editor.getAll;
newnames = fullfile(targetdir, {X.Filename}.');
[folder, baseFileNameNoExt, extension] = fileparts(newnames);
Fileswithextensions = strcat(baseFileNameNoExt,extension);
correctednames = fullfile(targetdir, Fileswithextensions.');
arrayfun(@(Info, NewName) Info.saveAs(NewName), X, correctednames)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Adding custom doc에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by