Assorted Stuff

by Greg Coombe



Here is some useful stuff that I've accumulated over the years. If you have any questions or find some errors, please email me.

Tensor Matlab Code

Here are a couple of Matlab functions for manipulating tensors, including multiplying them and performing a Higher-Order Singular Value Decomposition.
tmul.m svd3.m hopm.m flatten.m unflatten.m compare.m      

Matlab Sudoku Code

This was a little code that I wrote to play Sudoku, a surprisingly addictive numbers game. The code does a simple elimination scheme; no guessing, prediction, or branch-and-bounds. It can solve most simple games. A much more interesting solver is given here.
Main file fillBoard.m computeValid.m strategy1.m Sample board      

Outlining in Visual Studio .NET

Ever since I've started using Visual Studio 7, I've been annoyed at the "outlining" mode, which collapses and expands sections of code. I always inadvertently click on it when I'm trying to set a breakpoint or select and entire line. I just figured out how to turn it off: Go to Tools->Options->Text editor->C/C++->Formatting and de-select "Outlining mode". For some reason, this doesn't get rid of it in any open files, so you either have to close and open the files again, or use Edit->Outlining->Stop Outlining.

Testing whether a number is a power of two

This is from Steve Baker's Cute Code Collection. I use it all of the time for OpenGL texture stuff.
// Returns true if n is an integer power of 2.
static bool IsPowerOfTwo(int n) { return ((n&(n-1))==0); }

Cygwin exit gives error message

Does exiting Cygwin sometimes generate a "Terminate Batch Job(Y/N)" message? If so, you're probably using a Windows batch file to launch Cygwin. If the batch file doesn't consist of much, then just put all of that information directly into the shortcut. For me, this meant replacing the Cygwin shortcut:
C:\cygwin\cygwin.bat
to this:
C:\cygwin\bin\bash.exe --login -i

Cygwin: Can't quit Emacs using C-x C-c

On some installations of Cygwin on Windows XP, it is impossible to exit Emacs using C-x C-x. After digging around in the message lists, I found out that the C-x key is trapped by the OS. The fix for this is to set a Windows environment variable:
CYGWIN=tty
Then quit all of the Cygwin windows and start them up again. This worked for me.

Recovering Data From Matlab Figures

I save a lot of figures in Matlab as '.fig' files, so that I can export them to different formats later on. I usually forget how I got all of the data to generate the graph, or maybe the data came from long-running experiments. There should be a easy way to click on the data in the Matlab GUI and export it to the workspace, but so far I haven't found it. Josh Steinhurst discovered a different way to do it:
get( findobj('DisplayName', '{Data}'), 'Xdata');
where '{Data}' is the name of your data series (the name in the legend). If anyone has a more elegant way of doing this, please email me!

Fixing Corruption in CVS

I use CVS to backup my files and synchronize between my laptop and desktop. For a while, my binary files (such as PDFs and JPGs) were getting corrupted and I had no idea why. I eventually figured out that I was forgetting to specify 'binary' type when I checked in the files. There are two ways to fix this. You could always remember to specify '-kb' when you check them in, or you could use a "cvswrapper" file in the CVSROOT directory of your repository. This is a special file that always forces certain types of files to be binary. Here is my cvswrappers file. If you still have a couple of text files that should be binary, you can force them to binary by using
cvs admin -kb 
cvs update -A
A better way to do this is to use Subversion.


email at coombe@cs.unc.edu.