Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid matlab command history time stamp

I have a shell script that calls matlab in a for loop.

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

Now if I open matlab my command history will contain a short time stamp for each time I issued function_call in the for loop. For example after running the loop for 10 different i's, my matlab command history looks like this

%-- 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 --%

This is not very useful and it clutters my command history. Is there a way to avoid command history from adding a line each time matlab is launched from my shell script?

like image 727
ivan Avatar asked Oct 04 '22 05:10

ivan


1 Answers

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.

like image 162
Mohsen Nosratinia Avatar answered Oct 11 '22 13:10

Mohsen Nosratinia