File Exchange

image thumbnail


version 1.2 (10.9 KB) by Adam Danz
Search command history within and across Matlab sessions


Updated 18 Apr 2015

View Version History

View License

HxSearch.m allows user to search entire command history for key word(s) or phrase(s) and outputs full command lines containing the search item.
[SearchResults, NumCommandsAgo] = HxSearch (txtstr, specificity, max_output, session)
R = HxSearch ('save') >>> this will return a list of command history lines containing the word "save".
R = HxSearch ('save', 1) >>> this will return a list of command history lines beginning with the word "save".
R = HxSearch ('save', '', 50) >>> this will return up to 50 results (default is 20)
R = HxSearch ('save', '', '', 1) >>> this will only search your current session history
[R, N] = HxSearch ('save') >>> this also provides a vector of integers showing number of commands since R
Examples in use:
1) Display most recent 'load' command
[SearchRes, NumAgo] = HxSearch('load', 1, 1);
disp([SearchRes, ' was loaded ', num2str(NumAgo), ' commands ago.'])

2) re-load most recent file loaded
eval(HxSearch('load', 1,1));

3) see help HxSearch for more examples and information

In brief, Matlab versions earlier than R2014a save command history differently than current versions. This script works with both methods. See help HxSearch for more info.

My matlab vs is R2014a so please contact me if there are any bugs on other versions.

Cite As

Adam Danz (2021). HxSearch (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)



Ray Lee

Adam Danz

Here's another example of this function in use:

Calculate mean number of commands issued per session over the past x session then plot results in bar plot.

[~, NumCommands] = HxSearch('%-- ', 1, 50, 0);
MeanNumCommands = mean(diff(flipud(NumCommands)))
bar(diff(flipud(NumCommands))); xlabel('Number of sessions ago'); ylabel('Number of commands')

Adam Danz

Here's another example of this function in use:
List the 50 most recent date/times that matlab has been accessed:
dates = HxSearch('%-- ', 1, 50, 0)

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Save entire command history - Updated, Fast

Community Treasure Hunt

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

Start Hunting!