Create new workspace programatically

조회 수: 10 (최근 30일)
Wenjie Han
Wenjie Han 2018년 8월 20일
댓글: Stephen23 2018년 8월 21일
Is there any way to create a new workspace programatically just same as calling a function?
  댓글 수: 2
Rik
Rik 2018년 8월 20일
편집: Rik 2018년 8월 20일
What do you mean with workspace exactly? Because in the Matlab-definition of the word, it is automatically generated when you call a function. If you want to create a new base workspace, you can't. You can start a new instance of Matlab.
Really convoluted, but quite robust as well:
command_to_run=sprintf('"%s"',fullfile(matlabroot,'bin','matlab.exe'));
batfilename=[char(randi([97 122],1,8)) '.bat'];
while exist(batfilename,'file')
batfilename=[char(randi([97 122],1,8)) '.bat'];
end
fid=fopen(batfilename,'wt');
fprintf(fid,'%s\n',command_to_run);
fprintf(fid,'del /q "%%~dp0%s" 2>&1 >nul|findstr "^" >nul && exit || exit',batfilename);
fclose(fid);
system(sprintf('start %s',batfilename))
Stephen23
Stephen23 2018년 8월 21일
"...create a new workspace programatically just same as calling a function?"
Every function has its own workspace (nested and anonymous functions also access variables in the workspace where they are defined), so creating a new workspace just requires writing a function and calling it.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by