How do I search through MATLAB command history?

百般思念 提交于 2019-12-18 14:05:51

问题


I would like to search for a specific command I've previously used. Is it possible to do a free text search on MATLAB command history?


回答1:


If you want to accomplish this 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.




回答2:


Yes. Matlab stores your command history in a file called history.m in the "preferences folder," a directory containing preferences, history, and layout files. You can find the preferences folder using the prefdir command:

>> prefdir

ans =

/home/tobin/.matlab/R2010a

Then search the history.m file in that directory using the mechanism of your choice. For instance, using grep on unix:

>> chdir(prefdir)
>> !grep plot history.m
plot(f, abs(tf))
doc biplot
!grep plot history.m

You can also simply use the search function in the command history window if you just want to use the GUI.



来源:https://stackoverflow.com/questions/5053692/how-do-i-search-through-matlab-command-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!