フィルターのクリア

Clear text typed with input() from the command history

6 ビュー (過去 30 日間)
Oleg Komarov
Oleg Komarov 2014 年 6 月 10 日
編集済み: Oleg Komarov 2014 年 11 月 25 日
The case scenario is very simple, I am asking for a password to be typed in the command window.
I am using
s = input('Password: ','s')
I can clear the text from the command window with something like fprintf(char(8)), but how do I clear the last typed command from the command history ?
I am aware that inputdlg() would solve the problem but I would be interested in finding some way for editing the history.
EDIT
I personally changed approach from cmd window input to GUI input and wrote a submission for the purpose: http://uk.mathworks.com/matlabcentral/fileexchange/47210-passfield
  2 件のコメント
José-Luis
José-Luis 2014 年 6 月 10 日
編集済み: José-Luis 2014 年 6 月 10 日
A solution that's worse than the problem:
  1. Do your thing
  2. Close Matlab
  3. Modify the command history file history.m (delete last line). Use prefdir() to find where it is located.
  4. Reopen Matlab
I don't know if there's a way to force the IDE to update the command history. That way opening and closing Matlab wouldn't be necessary.
Oleg Komarov
Oleg Komarov 2014 年 6 月 10 日
I cannot afford to terminate the session, it's either disruptive or discretionary.
I am exactly looking for a way to refresh the IDE and I suspect that by digging into the java of the command history pane, it should be possible to find the callback for deleting one row which you can do if you select and right-click.

サインインしてコメントする。

採用された回答

Oleg Komarov
Oleg Komarov 2014 年 6 月 13 日
After digging into the Java internals with the help of Yair's toolkit (see findJObj, uiinspect and checkClass), I found a relatively simple way to manipulate entries in the Command History:
% Get instance to the Command History
cmdhist = com.mathworks.mde.cmdhist.AltHistory.getInstance;
% Retrieve the Command History Table
chtable = findjobj(cmdhist,'property',{'name', 'CommandHistoryTable'});
% Select last row row
nrows = chtable.getRowCount
chtable.setRowSelectionInterval(nrows, nrows)
% Delete selected rows
chtable.deleteSelectedCommands
  3 件のコメント
Rasmus
Rasmus 2014 年 11 月 19 日
I'm quite new to matlab and tires to use this code. There are one annoying side effect with the code. After the commands are executed the password will still be in the command window so i need to hit esc to not accidentally type the password again and then it is stored in the history.
How did you get around this?
Oleg Komarov
Oleg Komarov 2014 年 11 月 25 日
I recommend to use http://uk.mathworks.com/matlabcentral/fileexchange/47210-passfield for password related input in a GUI.

サインインしてコメントする。

その他の回答 (1 件)

Cedric
Cedric 2014 年 6 月 10 日
編集済み: Cedric 2014 年 6 月 10 日
It may be a bit violent but
com.mathworks.mlservices.MLCommandHistoryServices.removeAll
would work.
And welcome back! ;-)
  1 件のコメント
Oleg Komarov
Oleg Komarov 2014 年 6 月 10 日
Thanks Cedric! Yes, a bit violent. Can't afford to lose the whole history :).

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by