How to change Matlab settings (for history.m) in terminal? - matlab

I am using Matlab on a remote server from my MacBook. Partly because I find the Matlab GUI clunky under X11, I use it in the terminal window (by running matlab -nodesktop). This has been working fine, until I now needed to copy some stuff from the command history.
It seems like history.m is only being saved on exit, even though when I check the settings in the GUI, it says that it is being saved for each command. It also seems like exit statements are included in history.m when Matlab is run from terminal, but not in the GUI, so it seems like the settings in the GUI don't apply there. I cannot find anything in the Matlab help pages on how to change the settings for the terminal window.
I need to access the command history for my session while it is still open. Does anybody have an idea about how I can do this -- short of starting to use the GUI?

You might try the diary function. It logs both commands and their (text based) results to a file. On my system (Mac OSX with MATLAB R2011b), the output does not show up in the diary file immediately, but it does update when you turn off the diary. Which you can do repeatedly if you need without exiting matlab.

Related

When I edit a file with EMACS I get a strange error. How do I fix this?

This is what I am doing:
Make a file or use an existing file.
Emacs filename.txt.
Type some new text into the file.
Save file.
After step 2, I receive an error after the emacs editor window pops up.
Here is the error:
2022-01-19 22:11:53.935 Emacs-x86_64-10_14[33893:994906] It's not
legal to call -layoutSubtreeIfNeeded on a view which is already being
laid out. If you are implementing the view's -layout method, you can
call -[super layout] instead. Break on void
_NSDetectedLayoutRecursion(void) to debug. This will be logged only once. This may break in the future.
I have already tried updating emacs and that didn't help, and googling didn't give me an answer. Currently, I have GNU Emacs 27.1 version.
How do I fix this error?
As far as I know you shouldn't need to "fix" the error at all and it won't cause any problems while you're actually running Emacs. In fact I'm somewhat surprised you see it at all.
I was only able to see the error (in both Emacs 27 and in pretest-28.0.90) only by running the Emacs binary (eg. ./Emacs-27.app/Contents/MacOS/Emacs) directly from a terminal, which isn't the normal way of starting Emacs on macOS. If you just run Emacs by starting it from Finder, the Dock, or via the "open" utility then you shouldn't see the error at all, and it shouldn't cause any problems.
The whole point of keyboard interaction (and emacs in particular) is that there's no need to touch the mouse. It's possible to log in (using e.g. ssh) and edit remotely, with no gui (so no way to drag and drop), and this is the 'normal' way of invoking emacs. Run 'emacs --help' from the command line to see a bunch of options. In particular see 'emacs --no-window-system' which uses a raw terminal even when a gui is available (no error message appears when it's run this way).
The gui however adds font and image support, which can be useful if you're sitting at the machine. The error message you get when you invoke 'emacs' from the command line in its default mode, with no arguments, is a diagnostic describing a bug in the mac gui implementation.
The error's still there if you start emacs through the finder; you can see that by running (e.g.)
$ open /Applications/Emacs.app/Contents/MacOS/Emacs-x86_64-10_14
which both opens an emacs gui and a terminal window containing the program's text output.
As it says in the message, 'this may break in the future'; it's not helpful to say 'you're using it wrong.'

How to run MATLAB's code from Notepad++

I read this previous question What alternatives are there to the MATLAB Editor? and I am interesting in using another editor so I can also compile my codes with MATALB.
I did what the mentioned link suggested but I cannot see the difference. I went to Preferences Editor/Debbuger and I changed the editor to Notepad++ and nothing happened.
How can I use Notepad++ to compile and run MATALB codes?
P.S. I looked for "run matlab with notpad++" on google but did not find anything interesting.
Also my previous question is related (Can I use MATLAB editor without running MATLAB?).
I answered this a bit more thoroughly here: Running a MATLAB script from Notepad++
Use NppExec add-on and press F6, copy paste the following and save the script:
NPP_SAVE
set local MATPATH=C:\Program Files\MATLAB\R2015a\bin\matlab.exe
cd "$(CURRENT_DIRECTORY)"
"$(MATPATH)" -nodisplay -nosplash -nodesktop -r "try,
run('$(CURRENT_DIRECTOR)$(FILE_NAME)'), catch me, fprintf('%s /
%s\n',me.identifier,me.message), end"
When you mean run matlab code, if you just want to edit it and save and then run from MATLAB terminal, then you can use it just regularly as well. Save in notepad, run on MATLAB.
The problem arises when you want MATLAB editor features like debugger, and execute a block of code within %%. You cannot do all of it. You can set breakpoints, How to debug matlab code without gui
I think you wont get the other features of MATLAB editor if you use an external editor.

Matlab : open OS explorer window only if not already open

I'm opening a folder in Windows explorer from within matlab with the following line :
system('explorer.exe /select,./my_folder/my_file.tif');
It works well, even with the relative path for Matlab "current folder" with "./". Note that it also selects the specified file, which is what I want.
However, I would like to open this window only if the same path isn't already open. Right now, I get several copies of the same window and it's annoying. Do you know any way to do this ?
Thanks,
Ghislain
(Windows 8, Matlab R2011b 64bits)
Disclaimer
This is a partial answer. I don't know how to go on from here, but maybe it helps anyways. Your question is quite interesting to me, and it would make data-analysis a lot easier if changing between interfaces (Matlab/Explorer) were easier!
Some History
DDE is an ancient technology (16-bit Windows, yeah!) that enables Windows applications to talk to each other. DDE has been deperecated from Windows XP on, but it simply refuses to die.
One reason for DDE's longevity is that Windows Explorer still uses DDE a lot. For example, when you double-click a file, the Explorer sends a DDE command to Excel, telling it to open that file in the current Excel window.
How DDE might help you
Matlab's DDE support is officially deprecated. Maybe it would have disappeared completely, were it not for the fact that Explorer talks to Matlab via DDE messages!
You can reverse this process by telling initiating a DDE channel to the application "folders" about the topic "appproperties":
channel = ddeinit('folders', 'appproperties')
The "folders" application appears to be a synonym for "progman", the good ol' Windows 3 program manager. You can tell Explorer ("folders") to view a folder by executing
ddeexec(channel, '[ViewFolder("%l", c:\windows, 5)]')
If Explorer already points to that folder, no new window is opened. Unfortunately, I cannot tell you much more about that command. I don't know what that %l is doing there, or the 5 for that matter. The only thing I know is that ViewFolder can be replaced by ExploreFolder, in which case you always open a new window, and that window always shows the folder tree structure on the left pane.
More Information
The most important DDE-related functions are ddeinit, ddeexec, and ddeterm. Their documentation is buried inside the .m files of those functions. You can view the .m files by simply executing
edit ddeinit
Yair Altman has some more info on Matlab's DDE capabilities. What DDE commands are understdood by Explorer evades me. I assembled my example from what I found here.

Recover history MATLAB code?

I have a script named my_script.m, which has been mistakenly replaced by another file with the same name. However, prior to overwriting the script, I have run it in MATLAB console. Hence, I have the following history.
>> my_script
>>
Is there any way to recover that history file?
The reason why I think it is still possible is that I do have the run history of that script in my current console. If only I had selected all the script and run it! That way I would have every command in the console history. But now, it is simply one line as above.
Check if you had diary mode on, then everything is there:
get(0,'Diary')
You can open the file in windows explorer, right mouse button, properties. Then check if there are any other versions of the file in the Previous Versions tab ;)
Sometimes matlab writes backups, the file would be named my_script.asv. Check if it exists, it's located in the same directory.

Enter Perforce Commands in p4v GUI

Is there a way to manually enter perforce commands in the p4v GUI?
I'm relatively new to Perforce and find the GUI useful for most of what I need to do, but I can see situations where a one line command would be much easier than navigating through the GUI.
Example:
Opening a file for edit that is nested deep in the source tree; this takes many clicks when done in the GUI but would be a relatively short command with environment variables set for my most commonly used directories.
p4 edit -c NNNNNN $DIRECTORY/file
It would be great if the command entered was also added to the Log window. I really like being able to scroll through the Log to see everything I've done in a session.
The closest that exists right now is "File"->"Open Command Window Here" when you have a file selected in the file browsing pane. It will open a command line in that file's directory with all of the relevant environment set up.
Unfortunately, this won't give you unified Log, and you'll have to juggle a second window.