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
Related
I'm looking for a solution to copy the command prompt's current content to the clipboard. I know something similar is possible by redirecting the output or using clip but I'm looking for something else. I'm looking for a command which copies the entire content of the command prompt window to the clipboard/a file anytime when it's called(not just the output of one command). It's quite easy to do manually by selecting everything and press ctrl-c but I need a command for this.
Basically it should achieve the same as doskey /history > somefile.txt but saving the output of the commands too.
Is something like this possible?
you can use simple java program , to get the entire content of the command prompt and out it into a String variable or write it to txt file
For example: Rstudio uses so called projects - text files ending with .Rproj. When you click on a project file, it opens up Rstudio and sets working dir to where the project file is. Optionally, it executes any code written it. However, it does not open itself (i.e., it does not show up in the script editor).
Is there something like that in Matlab? If not, how to emulate it?
Currently I use to make an .m file with cd, addpath calls etc. But when I click in the file browser:
it just opens Matlab and shows up in the script editor without running
opening Matlab is what I want, but showing up in the script editor is actually redundant; I only need to run it (and use the results in my Matlab desktop session)
(What I want to avoid is having to open the script file, run it manually and then having to close it again. It is annoying!)- edited
Matlab does not have "project files" (as far as I know).
However, I think you can easily emulate what you want.
Let's suppose you have your code in a folder C:\MyProject:
1) Create a new m-file C:\MyProject\MyProject.m with all your initialization code (cd, addpath calls, global variables, whatever you need).
Here's a simple example for demonstration purposes:
disp('Replace this with your initialization code');
2) Create a batch-file C:\MyProject\MyProject.bat as follows:
MATLAB -r "run MyProject"
Now, by double-clicking the batch-file you will:
open the complete Matlab environment
execute the script MyProject.m (without loading it in the script editor)
For this purpose, MATLAB offers startup.m files (online documentation).
You have to put all your initialization code in a file called startup.m, which needs to be located within the MATLAB search path (i.e. within your project folder). The script will be executed every time you open MATLAB by double-clicking a arbitrary m-file from your project folder.
According to this link:
How to save contents of MATLAB's command windows to in a file?
I can back up my commends going forward using diary which is great:
However I would also like to back up my existing command history, I assume the command history is stored in a text file somewhere correct?
If so can I just copy this?
Type prefdir on Matlab and it will give you a folder.
Your command history is in that folder, in a file called history.m.
Have a look at the "Save Entire Command History" submission, which will let you save all your command history, not just the last 20k allowed by MATLAB.
So I have a file I open using emacs with 1000+ lines that contains columns of data. Is there a way to highlight everything (all lines) in the file so that I may copy and paste to my internet browser (such as in email)?
You can do Ctrl-x h Meta-w to select everything and copy it.
Ctrl-x h selects everything, and Meta-w will copy whatever is selected.
Meta+x mark-page you can typically also use Ctrl+x Ctrl+p to select the page
followed by
Meta+w
to copy the marked region, in this case the entire page.
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...