how to exclude, or remove, input response from command history?

I have a function that uses "input()" to get a user response. Is there a way to not record the value returned from "input()" in the command history? Alternatively, is there a way to "remove" the response from the command history?
in the command window I get:
select this line (s to select, d for done, c for clear) : c
rply =
'c'
select this line (s to select, d for done, c for clear) : s
rply =
's'
select this line (s to select, d for done, c for clear) : d
rply =
'd'
or if I suppress the display of "rply" by inserting a semicolon in the code the command window is:
select this line (s to select, d for done, c for clear) : c
select this line (s to select, d for done, c for clear) : s
select this line (s to select, d for done, c for clear) : d
In either case, the command history shows:
inspect_outliers_test(1)
c
s
d
inspect_outliers_test(1)
c
s
d
What I would like to do is suppress, or remove, the user typed response ("rply" value) from the command history. The reason is that there may be many user responses generated inside a loop and it just clutters up my command history. It would be nice if there was a setting to toggle the saving of user input (via "input()") in the command history, but I have not been able to find it.
Any suggestions?

Respuestas (2)

Image Analyst
Image Analyst el 1 de Feb. de 2018
To remove commands you have run from your command history, click on the command window prompt and hit the up arrow. Then scroll up to the command you no longer want to show up and right click on it. Select "delete" and it will no longer appear in your command history.
Alternatively you can remove it from the History.xml file manually with a text editor. If you have Windows, edit the file "C:\Users\yourName\AppData\Roaming\MathWorks\MATLAB\R2017b\History.xml" with something like Notepad, and delete the lines you don't want in your history.

2 comentarios

Yes, it is possible to manually remove the "input()" responses from the "Command History" -- but it requires manipulations after the fact. It just seems to me that responses to "input()" are not really 'commands' at all and should not automatically be saved in the "Command History" or we should be able set this as a preference.
Maybe there is no mechanism to alter this behavior, but that is what I was asking about.
Maybe but I don't know how to do it. And generally I don't care what goes into my history log. If you do, then call the Mathworks - maybe there is a way to turn off the history in code. As you can see from the preferences, there is a way to turn it off from the dialog box.
Maybe you can turn it off prior to calling input() and turn it back on after you call input().
You might find an answer from Yair's undocumented MATLAB site: https://undocumentedmatlab.com/blog/changing-system-preferences-programmatically or just ask the Mathworks directly.

Iniciar sesión para comentar.

Jan
Jan el 31 de En. de 2018
Do not use the command history for complicated user defined logging. This is not its purpose. If you want to log data, creating a dedicated log file is more secure and efficient. Using input to insert data makes it much harder to impossible to reproduce your results. Better create a GUI or define the input data as files or by code, such that they can be provided as input arguments. Then recording the values is much easier and you do not have to try any tricks to manipulate the command window history.

5 comentarios

I agree.
But in this case I actually was asking about the opposite of logging. By default, Matlab logs the responses to "input()" in the "Command History" buffer/file -- I would like to suppress this default behavior programmatically, or with a "preference", within some of my code.
@Dave: My point was, that you do not have to clean up specific lines from the history, if you do not use the history at all. Let the history as it is, and use a special tool for creating the logs you need.
If you use an inputdlg instead of input in the command window, you do not get an entry in the history also.
Problem is I find using the Command History incredibly useful for many things...I just get annoyed at having to scroll past all the "input()" responses to get to the statement that called the function, or script, that contains the "input()" command(s).
For example, I have a function that processes and produces many different plots. After each plot I ask (using input) if the user wants to print, save, embellish, etc the plot -- such as:
> Print (y), Fix (f), Copy (c), Save (s), Close (x), or New figure (n) ? :
every 'y', 'f', 'c', 's', or 'x' typed by user in response to these prompts ends up in the "Command History" -- even though they are not "commands" at all.
I appreciate that suggestion to look at "inputdlg()" as an alternative -- perhaps Mathworks can provide links, or a mention, of the "dlg" functions in the help for "input()" as alternatives. For this alternative I will go ahead and accept this answer.
Mathworks can provide links, or a mention, of the "dlg"
functions in the help for "input()" as alternatives.
See doc input, in the "See also" line at the bottom, where inputdlg is mentioned. These "See also" hints are very useful to find a matching Matlab command.
If it really bugs you, you can make an m-file called filter_history.m where you open the history.xml file, extract out only the items you want, write out out to a temporary file, delete the original history file, and rename the temporary file to history.xml. You could put the call to that filter_history function in your startup.m file. Of course it would remove only the undesired functions up to the present session, not those in the present session.

Iniciar sesión para comentar.

Categorías

Más información sobre Entering Commands en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 31 de En. de 2018

Comentada:

el 3 de Feb. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by