5

我有一个在 for 循环中调用 matlab 的 shell 脚本。

for i in ${list}; do 
    nohup matlab -minimize -nodesktop -nosplash function_call(i, other_variables);
done

现在,如果我打开 matlab,我的命令历史记录将包含我每次在 for 循环中发出 function_call 的短时间戳。例如,在为 10 个不同的 i 运行循环后,我的 matlab 命令历史看起来像这样

%-- 08/19/2013 02:41:23 PM --%
%-- 08/19/2013 02:53:11 PM --%
%-- 08/19/2013 03:11:52 PM --%
%-- 08/19/2013 03:12:58 PM --%
%-- 08/19/2013 03:17:44 PM --%
%-- 08/19/2013 03:24:51 PM --%
%-- 08/19/2013 03:30:36 PM --%
%-- 08/19/2013 03:35:33 PM --%
%-- 08/19/2013 03:43:21 PM --%
%-- 08/19/2013 04:04:31 PM --%

这不是很有用,而且会弄乱我的命令历史记录。有没有办法避免每次从我的 shell 脚本启动 matlab 时添加一行命令历史记录?

4

1 回答 1

4

You can put this script in your startup.m file to remove those lines when MATLAB starts:

H.file = fullfile(prefdir, 'history.m');
copyfile(H.file, [H.file '.bak'], 'f');
H.log = fileread(H.file);
H.handle = fopen(H.file, 'w');
H.stat = fwrite(H.handle, regexprep(H.log, '(%-- [^%]* --%(\n|\r)*)*', ''));
H.stat = fclose(H.handle);
clear H 

The file that contains the history is located in preference folder prefdir and named history.m. The rest is a regular expression that matches those lines in the end of file. I put all variables in the script into a structure so that I can clear them all by clear H. H.stat = is used to avoid creation of ans variable.

于 2013-08-19T21:23:44.817 回答