I have a command in the command line of Matlab which is longer than just one line but when recalling it by pressing arrow-up, I just can go through every single line of the multiline-code... Is there a way to recall the complete last execution, no matter if just single or multiline?!
thanks!
In the Command History window, highlight the relevant lines and press F9 (or right-click and select Evaluate Selection if your shortcuts differ from mine).
The simplest solution is to right click the particular line in the command history window and select Copy or Evaluate Selection :)
If you'd like to copy a significant portion of your history, then you can output the contents of your history file (which is stored in history.m in the preferences directory) to the command window and copy from there.
type([prefdir '/history.m'])
%-- 20/6/11 3:17 PM --%
clc
outputVariable=someVeryLongFunctionNameThatMakesNoSense(inputVar1,'inputString1',inputVar2)
type([prefdir '/history.m'])
The above command and the screenshot were on a Mac. As always, be careful with the / on Windows. I can never remember which way it leans...
Related
Is there a method to store the command line outputs to a file in Julia.
The command history can be seen at .julia\logs\repl_history.jl in Windows OS.
I wish to store command line output also to a file automatically.
? command outputs also.
Whatever is shown in the julia command line, the whole text should be stored into a file.
Is there a way to do this.
found a similar qn : For Julia saving output to txt/CSV file?
If you run Julia in REPL mode in Widows using PowerShell, you can do the following in PowerShell:
Open the left upper corner menu and in Defaults, change the buffer size to something large enough for your needs, say 500.
After running Julia to do what you need, go the the left hand corner menu and choose Edit - Select all, then Copy. Paste to an editor.
typing and executing a single line command in octave cli is simple.
for example a=1.
If one wants to edit this command and execute it again it is possible by navigating the history with the up/down keys.
But when executing a multi line command-script, one can still navigate to a single line and edit it, but how to execute the all script again, without going line by line in the history and "enter" the line?
for example:
for i=1:6
a(i) = i;
end
Is there a way to open the all script in an editor, edit, and re-execute it?
Yes there is, via the history command.
E.g. history -q 3 will display the last 3 commands -- the -q switch means do not prepend line numbers, such that the output is copy-pasteable.
You can also use the -w switch to redirect the output to a file, which you could then modify in your editor and call as a script, as you suggest.
If you're using the GUI, you can also use the history pane to highlight the lines you're interested in (in the order that you want them!), and paste directly into the editor window.
I know how to save variables in matlab by this command
save
and load it by this command
load
but the question how to copy history of commands in txt file
save won't save commands, it saves the variables in your current workspace.
MATLAB history is saved in a History.xml file, the directory can be viewed by prefdir command.
For plain .txt command, just press up-arrow, and select-all from the history small list, copy it to whatever place you want. You may find this documentation helpful.
Just in case you do not have access to the admin folders or don't have required previleges,here's a simple method that worked for me,accidentally.
Go to the command prompt
and press CNTRL+A (Select All) and then CNTRL+C(Copy)
You will be prompted that :
It is not possible to show 13xx commands on the screen,
Go ahead anyway.
Then simply CNTRL + V (Paste) everything in any text editor.
Voila!
Hope it helps,
Anuj
I was checking the original 'clc.m' file in MATLAB. Apparently the function is written as a p-code and you just see the description which is placed in:
..\MATLAB\R2013a\toolbox\matlab\iofun\clc.m
How can I take a look at the original code?; however this is not the main question, it is just for fun.
The main point is I am looking for a way to reverse the clc process, after you clean the screen. Is there any way to reverse the clc process. The same question goes for clear all as well.
Try using home instead of clc. Whereas clc removes all text from the Command Window and moves the cursor to the top left giving you a blank window, home just moves the cursor to the top left and gives a you a blank window - but the text is still there, and you can scroll up to see it. I use home all the time rather than clc.
In either case, the text remains in the Command History window, and can be retrieved in the Command Window using the Up/Down arrows.
The reason you can't see the code behind clc is not that it's p-coded, it's that it's a built-in function (i.e. not implemented in the MATLAB language). The same is true for clear, and also many math functions such as svd, eig etc. There's no way to modify them to change what they do (such as reversing the process).
Edit: You might also like to look into the diary function, which keeps a log of all the input and output at the command window in a specified file. I have the following lines in my startup.m file (type doc startup if you don't know how to use MATLAB startup files):
diaryFolder = 'C:\diaries';
diaryFileName = ['diary', datestr(now, 'yyyymmdd'), '.txt'];
diary(fullfile(diaryFolder, diaryFileName))
So whenever I start MATLAB, it's automatically capturing all command window input and output to a diary file that's named by the date - If I start MATLAB multiple times a day, it just appends to the same file. I can clc or home whenever convenient, and there's always a record kept of everything that I can search through if necessary.
I don't believe there would be anyway to undo the clc process. That said, it is possible to still view the command history, so that might get you somewhere.
Once you clear the data, I believe it's gone forever. I highly doubt that data is stored in memory somewhere. I know that after a certain number of lines, the history is deleted. So your best bet is to start figuring out how large that buffer is and proceed from there to see if you can find anything interesting.
A lot of the code that I write in Matlab has a very verbose output. As the program runs, information is printed to the command window, and with each new line, the window automatically scrolls to the bottom. This becomes a problem when I want to read some of the output more closely or scroll up to look at older output. I can scroll up, but only until a new line is printed, which is often less than a second.
Does anyone know if it is possible to turn off this automatic scrolling in the Matlab window? I work in a number of different Matlab versions, depending on the machine, and this happens with all of them. The answer to this might be "No", but I swear I remember having this functionality at one point.
Use the more function: http://www.mathworks.com/help/matlab/ref/more.html
more on
Then run your program. Press spacebar when you wish to see more of the output.
more off will turn it off.
You may find this workaround useful.
First launch matlab using the command line matlab -logfile 'myLog.txt' (the doc says it "starts MATLAB and makes a copy of any output to the Command Window in filename. This includes all crash reports.")
Then open your .txt file using a text editor supporting automatic refresh of content (see picture). On OSX I use TextWrangler (freely available at www) but others have been reported to have this feature (see here or here).
Results: output displays (fprintf, disp, but not the commands per se) are printed both on the Matlab console and the text editor (file is refreshed with a little lag time, below half a second I would say with my configuration). And there is no automatic scrolling. Such procedure does not seem to impact the overall performance of the script (although it may deserve some testing).