How do I search through MATLAB command history?

前端 未结 2 1910
灰色年华
灰色年华 2021-01-01 14:35

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?

2条回答
  •  猫巷女王i
    2021-01-01 15:10

    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.

提交回复
热议问题