Search the Matlab history

If you ever need to search through the MATLAB command history you can do it in the following way.

To accomplish it in a programmatic and platform-independent manner, you can first use MATLAB’s Java internals to get the command history as a character array:

history = com.mathworks.mlservices.MLCommandHistoryServices.getSessionHistory;
historyText = char(history);

Then you can search through the character array however you like, using functions like STRFIND or REGEXP. You can also turn the character array into a cell array of strings (one line per cell) with the function CELLSTR, since they can sometimes be easier to work with.

via How do I search through MATLAB command history? – Stack Overflow.

Changing the last line to .getAllHistory should get you the whole history, whereas the previous one will get you just the history from the current session.

history = com.mathworks.mlservices.MLCommandHistoryServices.getAllHistory;

If you liked this post please leave a comment or consider subscribing.

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s