File Exchange

image thumbnail


version (15.3 KB) by jiro
LOOKFOR substitute that uses a database for quick searching of MATLAB® files.

1 Download

Updated 01 Sep 2016

View Version History

View License

Editor's Note: This file was a File Exchange Pick of the Week

LOOK4 Quick-search M-files with keywords using a database.
LOOK4 ABC XYZ ... looks through a database of help files (H1 lines in m-files) for keywords ABC, XYZ, ... There can be as many keywords as desired. For all files in which a match occurs, the H1 line is displayed. CLASS METHODS will be indented by one space, and PRIVATE function will be indented by two spaces.

LOOK4 is very similar to LOOKFOR, except that it searches through a database file named mfileDatabase#.mat (where # is the version number), so it is much faster. Also, unlike LOOKFOR it accepts multiple keywords. The search is case-insensitive.

mfileDatabase#.mat is created the first time LOOK4 is executed. It catalogs helt texts of all m-files in the MATLABPATH (including class methods and private functions). The database file is stored in the same directory as this file. The generation of the database file may take a few minutes depending on the number of m-files and the speed of the computer.

LOOK4 ABC XYZ ... -all : searches the entire first comment block of m-files.
LOOK4 ... -link : displays the results with hyperlinks to full help texts

LOOK4 -new : re-creates the database file.
LOOK4 -new -noverbose : does not show the name of the directory in progress.
LOOK4 -update : updates the database file for the current directory. This is useful for updating personal m-files.
LOOK4 -autoupdate : sets up auto-updating feature.

How Auto-Updating of Database Works:
The database can be set to tomatically update (re-hash) daily or weekly. LOOK4 accomplishes this by creating a function called look4_autoUpdateFcn.m that gets run during startup (The call is appended to startup.m. If startup.m does not exist, it creates one). This function creates a TIMER object (tagged 'look4AutoUpdateTimer') that gets executed at the appropriate time and interval. Matlab needs to be running at the time of execution. If Matlab is launched after the scheduled update time, then the timer will be scheduled to execute at the next update time.
LOOK4 also checks the age of the database file (by checking the modification date), and gives a warning when 2 weeks has passed since the last modification. This feature creates a dummy file "mfileDatabase#_vt.txt" which is used to store the time when the warning was displayed.

[H, P] = LOOK4('ABC', 'XYZ', ...) returns the H1 lines and the paths of the corresponding m-files, respectively.

LOOK4 by itself invokes a GUI version of the search program. The GUI incorporates a "key stroke" search feature. Each key stroke updates the search result, but only after 0.5 seconds of non-keypress. This allows fast, continuous typing. Only alphabets and numbers (and quotes) are allowed in the GUI version. Click on results list, or use arrow keys to navigate through results. The full help text is displayed in the bottom panel.

look4 root locus
look4 root locus -all


This is a remake of my WHEREIS code (also found in FEX).

Cite As

jiro (2021). LOOK4 (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (9)

Dan K

A few recommendations:
On line 654: disable 'resize','off' if you use dual monitors (and might want to use look4 on your second monitor). Also, if you default to docked figures, include 'WindowStyle','docked'

As a bug note: in R2011b, if I hit the clear button in the GUI, then look4 becomes completely unresponsive, and I must close it and start over.

Brian Katz

The try-catch syntax has changed in MatLab. This file needs to be revised to function correctly.

>> look4
??? Warning: File: look4.m Line: 1044 Column: 11
This try-catch syntax will continue to work in R2007a,
but may be illegal or may mean something different in future releases of MATLAB.
See Release Notes for MATLAB Version 7.4, "Warning Generated by try-catch" for details.

>> version
ans = (R2007a)

Ludger Fork

Thank you for sharing this. Love it.

Óttar Ísberg

Jiro Doke

A new version is on the way. This version allows auto-updating of the database, and other minor improvements. The version number should be v1.4 (shown below the first comment block).

Jiro Doke


It's not quite obvious, but you can find whole words by typing:

look4 'sinc ' -all

Note the quotes and the forced space after the word.

Thanks for your idea about hyperlinks. I'll try to incorporate it in the next version.

Iram Weinstein

A problem: I tried look4 sinc -all and generated 85 hits because look4 accepts partial word hits like since. I suggest making full word the default.

Also, here's a way to make the path to the hits more accessible, using matlabcolon. It presents the keywords as hyperlink text. Clicking on the keword shows the full path to the file.

function look4wrap(varargin)


if isempty(H)
disp('None found.')
for k=1:length(H)
disp(['<a href="matlab: disp(''' P{k} ''')">' H{k} '</a>'])

Michael Robbins

Much needed function. LOOKFOR is painfully slow.

John D'Errico

A splendid enhancement over lookfor if your files are spread over a network. The initial cache call will take a while, but then its fast. Allowing multiple keywords is also nice. Just remember to renew its cache periodically. (An idea would be to add a time stamp in the database, then have it redo the database whenever it is called and the database is over the uder settable age limit. Another idea would be an option to have it establish a timer to redo the database at user specified times. Thus if you leave your matlab process running over night, you could set it to kick in at midnight.)

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

Community Treasure Hunt

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

Start Hunting!