gpt4 book ai didi

matlab - 避免 matlab 命令历史时间戳

转载 作者:太空宇宙 更新时间:2023-11-03 19:44:55 24 4
gpt4 key购买 nike

我有一个在 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's 运行循环后,我的 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 时,有没有办法避免命令历史记录添加一行?

最佳答案

您可以将此脚本放入您的 startup.m文件以在 MATLAB 启动时删除这些行:

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

包含历史记录的文件位于首选项文件夹中 prefdir并命名为history.m .其余的是匹配文件末尾那些行的正则表达式。我将脚本中的所有变量放入一个结构中,以便我可以通过clear H 将它们全部清除。 H.stat = 用于避免创建 ans 变量。

关于matlab - 避免 matlab 命令历史时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18322360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com