# Benjamin Oakes

Hi, I'm Ben Oakes and this is my geek blog. Currently, I'm a Ruby/JavaScript Developer at Liaison. Previously, I was a Developer at Continuity and Hedgeye, a Research Assistant in the Early Social Cognition Lab at Yale University and a student at the University of Iowa. I also organize TechCorridor.io, ICRuby, OpenHack Iowa City, and previously organized NewHaven.rb. I have an amazing wife named Danielle Oakes.

Filtering for the Matlab category. Clear

### Plot inverse colors in Matlab?

by Ben

I’m plotting on top of an image in Matlab. Sometimes, I can’t see what’s being plotted because the color of the image underneath is too close to the color of the image at the same location. I could just always change the color of the plot (e.g. from ‘rx’ to ‘bx’), but that’s cumbersome.

Is it possible to plot the inverse color of what’s underneath so that the overlay is always visible?

### How do I do multiple assignment in MATLAB

by Ben

Here’s an example of what I’m looking for:

``````>> foo = [88, 12];
>> [x, y] = foo;``````

I’d expect something like this afterwards:

``````>> x

x =

88

>> y

y =

12``````

But instead I get errors like:

``??? Too many output arguments.``

I thought `deal()` might do it, but it seems to only work on cells.

``````>> [x, y] = deal(foo{:});
??? Cell contents reference from a non-cell array object.``````

How do I solve my problem? Must I constantly index by 1 and 2 if I want to deal with them separately?

### What’s the closest thing to #define in Matlab?

by Ben

In C, I might do something like this:

``````#define MAGIC_NUMBER (88)

int foo(int a, int b, int c) {
return a + b + c + MAGIC_NUMBER;
}

double bar(double x, double n) {
return x + n + MAGIC_NUMBER;
}

/*
* ...and so on with many kind-of-long functions using
* MAGIC_NUMBER instead of writing a literal 88 like so:
*/

double bar(double x, double n) {
return x + n + 88;
}``````

What should I do in Matlab? (Needs to work across multiple files.)

### How to organize MATLAB code?

by Ben

How do you organize your Matlab code? I’ve come into ownership of several thousand lines of Matlab code, some as >900 line functions and a few directories full of `function_name.m` files. It’s hard to figure out what everything is doing (or relating to) or figure out the dependencies. I’d like to reorganize things as I figure out what does what, but Matlab limits what’s possible. What would you suggest?

### Constants in MATLAB

by Ben

I’ve come into ownership of a bunch of Matlab code and have noticed a bunch of “magic numbers” scattered about the code. Typically, I like to make those constants in languages like C, Ruby, PHP, etc. When googling this problem, I found that the “official” way of having constants is to define functions that return the constant value. Seems kludgey, especially because Matlab can be finicky when allowing more than one function per file.

Is this really the best option?

I’m tempted to use / make something like the C Preprocessor to do this for me. (I found that something called `mpp` was made by someone else in a similar predicament, but it looks abandoned. The code doesn’t compile, and I’m not sure if it would meet my needs.)