如何搜索MATLAB命令历史记录?

时间:2011-02-19 21:34:44

标签: search matlab history

我想搜索我之前使用过的特定命令。是否可以在MATLAB命令历史记录上进行自由文本搜索?

2 个答案:

答案 0 :(得分:25)

是。 Matlab将您的命令历史记录存储在“首选项文件夹”中名为history.m的文件中,该文件包含首选项,历史记录和布局文件。您可以使用prefdir命令找到首选项文件夹:

>> prefdir

ans =

/home/tobin/.matlab/R2010a

然后使用您选择的机制搜索该目录中的history.m文件。例如,在unix上使用grep:

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

如果您只想使用GUI,也可以使用search function in the command history window

答案 1 :(得分:7)

如果要以编程和平台无关的方式完成此任务,可以先使用MATLAB's Java internals将命令历史记录作为字符数组:

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

然后,您可以使用STRFINDREGEXP等功能搜索您喜欢的字符数组。您还可以使用函数CELLSTR将字符数组转换为字符串的单元格数组(每个单元格一行),因为它们有时可以更容易使用。

相关问题